summaryrefslogtreecommitdiff
path: root/src/journal
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/journal
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/journal')
-rw-r--r--src/journal/coredumpctl.c2
-rw-r--r--src/journal/journalctl.c2
-rw-r--r--src/journal/test-catalog.c9
-rw-r--r--src/journal/test-mmap-cache.c7
4 files changed, 12 insertions, 8 deletions
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 <stdlib.h>
#include <unistd.h>
#include <errno.h>
+#include <fcntl.h>
#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 <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
+#include <fcntl.h>
#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);