From 2d5bdf5bc0e4714d42e5999a4e37553a6bf83575 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 28 Jan 2014 13:47:35 +0100 Subject: always use the same code for creating temporary files Let's unify our code here, and also always specifiy O_CLOEXEC. --- src/journal/coredumpctl.c | 2 +- src/journal/journalctl.c | 2 +- src/journal/test-catalog.c | 9 ++++++--- src/journal/test-mmap-cache.c | 7 ++++--- 4 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/journal') diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index e564ab656c..3bceb48ff7 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -472,7 +472,7 @@ static int run_gdb(sd_journal *j) { data = (const uint8_t*) data + 9; len -= 9; - fd = mkostemp(path, O_WRONLY); + fd = mkostemp_safe(path, O_WRONLY|O_CLOEXEC); if (fd < 0) { log_error("Failed to create temporary file: %m"); return -errno; diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 2d99ade117..482795bd38 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -1286,7 +1286,7 @@ static int setup_keys(void) { n /= arg_interval; close_nointr_nofail(fd); - fd = mkostemp(k, O_WRONLY|O_CLOEXEC|O_NOCTTY); + fd = mkostemp_safe(k, O_WRONLY|O_CLOEXEC); if (fd < 0) { log_error("Failed to open %s: %m", k); r = -errno; diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c index ffe180265b..b087a8b81c 100644 --- a/src/journal/test-catalog.c +++ b/src/journal/test-catalog.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "util.h" #include "log.h" @@ -45,7 +46,9 @@ static void test_import(Hashmap *h, struct strbuf *sb, const char* contents, ssize_t size, int code) { int r; char name[] = "/tmp/test-catalog.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, contents, size) == size); @@ -98,10 +101,10 @@ static void test_catalog_importing(void) { static const char* database = NULL; static void test_catalog_update(void) { + static char name[] = "/tmp/test-catalog.XXXXXX"; int r; - static char name[] = "/tmp/test-catalog.XXXXXX"; - r = mkstemp(name); + r = mkostemp_safe(name, O_RDWR|O_CLOEXEC); assert(r >= 0); database = name; diff --git a/src/journal/test-mmap-cache.c b/src/journal/test-mmap-cache.c index e2ffaf4723..7d03bfe9d1 100644 --- a/src/journal/test-mmap-cache.c +++ b/src/journal/test-mmap-cache.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "log.h" #include "macro.h" @@ -36,15 +37,15 @@ int main(int argc, char *argv[]) { assert_se(m = mmap_cache_new()); - x = mkstemp(px); + x = mkostemp_safe(px, O_RDWR|O_CLOEXEC); assert(x >= 0); unlink(px); - y = mkstemp(py); + y = mkostemp_safe(py, O_RDWR|O_CLOEXEC); assert(y >= 0); unlink(py); - z = mkstemp(pz); + z = mkostemp_safe(pz, O_RDWR|O_CLOEXEC); assert(z >= 0); unlink(pz); -- cgit v1.2.3-54-g00ecf