summaryrefslogtreecommitdiff
path: root/src/test/test-unit-file.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-01-28 13:47:35 +0100
committerLennart Poettering <lennart@poettering.net>2014-01-28 13:47:35 +0100
commit2d5bdf5bc0e4714d42e5999a4e37553a6bf83575 (patch)
treeea5e964d2761f1dcd29ba9bb53b869569a6292bf /src/test/test-unit-file.c
parent7736202ce9149942e96e525c08d508daa448aff5 (diff)
always use the same code for creating temporary files
Let's unify our code here, and also always specifiy O_CLOEXEC.
Diffstat (limited to 'src/test/test-unit-file.c')
-rw-r--r--src/test/test-unit-file.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
index 1b4133b5d3..a8d5b65e6d 100644
--- a/src/test/test-unit-file.c
+++ b/src/test/test-unit-file.c
@@ -25,6 +25,7 @@
#include <stddef.h>
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
#include "install.h"
#include "install-printf.h"
@@ -221,7 +222,9 @@ static void test_load_env_file_1(void) {
int r;
char name[] = "/tmp/test-load-env-file.XXXXXX";
- _cleanup_close_ int fd = mkstemp(name);
+ _cleanup_close_ int fd;
+
+ fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
assert(fd >= 0);
assert_se(write(fd, env_file_1, sizeof(env_file_1)) == sizeof(env_file_1));
@@ -242,7 +245,9 @@ static void test_load_env_file_2(void) {
int r;
char name[] = "/tmp/test-load-env-file.XXXXXX";
- _cleanup_close_ int fd = mkstemp(name);
+ _cleanup_close_ int fd;
+
+ fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
assert(fd >= 0);
assert_se(write(fd, env_file_2, sizeof(env_file_2)) == sizeof(env_file_2));
@@ -258,7 +263,9 @@ static void test_load_env_file_3(void) {
int r;
char name[] = "/tmp/test-load-env-file.XXXXXX";
- _cleanup_close_ int fd = mkstemp(name);
+ _cleanup_close_ int fd;
+
+ fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
assert(fd >= 0);
assert_se(write(fd, env_file_3, sizeof(env_file_3)) == sizeof(env_file_3));
@@ -270,10 +277,11 @@ static void test_load_env_file_3(void) {
static void test_load_env_file_4(void) {
_cleanup_strv_free_ char **data = NULL;
+ char name[] = "/tmp/test-load-env-file.XXXXXX";
+ _cleanup_close_ int fd;
int r;
- char name[] = "/tmp/test-load-env-file.XXXXXX";
- _cleanup_close_ int fd = mkstemp(name);
+ fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
assert(fd >= 0);
assert_se(write(fd, env_file_4, sizeof(env_file_4)) == sizeof(env_file_4));