summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-06-17 23:50:22 +0200
committerLennart Poettering <lennart@poettering.net>2014-06-18 00:09:46 +0200
commit1554afae546f6cfb8ac85e36300d7bf608886780 (patch)
treebfd0db047b46192676832426d278da277187e752 /src/shared
parent0a498f163ab371ca34b4fe2c1ec8a67e2bb83fe8 (diff)
tmpfiles: add "+" modifier support to b, c, p lines in addition to L
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c40
-rw-r--r--src/shared/util.h2
2 files changed, 42 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index fe05820395..bce4e634c2 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4145,6 +4145,46 @@ int symlink_atomic(const char *from, const char *to) {
return 0;
}
+int mknod_atomic(const char *path, mode_t mode, dev_t dev) {
+ _cleanup_free_ char *t = NULL;
+
+ assert(path);
+
+ t = tempfn_random(path);
+ if (!t)
+ return -ENOMEM;
+
+ if (mknod(t, mode, dev) < 0)
+ return -errno;
+
+ if (rename(t, path) < 0) {
+ unlink_noerrno(t);
+ return -errno;
+ }
+
+ return 0;
+}
+
+int mkfifo_atomic(const char *path, mode_t mode) {
+ _cleanup_free_ char *t = NULL;
+
+ assert(path);
+
+ t = tempfn_random(path);
+ if (!t)
+ return -ENOMEM;
+
+ if (mkfifo(t, mode) < 0)
+ return -errno;
+
+ if (rename(t, path) < 0) {
+ unlink_noerrno(t);
+ return -errno;
+ }
+
+ return 0;
+}
+
bool display_is_local(const char *display) {
assert(display);
diff --git a/src/shared/util.h b/src/shared/util.h
index 73f7c0ad4c..6ad43cd274 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -523,6 +523,8 @@ int terminal_vhangup(const char *name);
int vt_disallocate(const char *name);
int symlink_atomic(const char *from, const char *to);
+int mknod_atomic(const char *path, mode_t mode, dev_t dev);
+int mkfifo_atomic(const char *path, mode_t mode);
int fchmod_umask(int fd, mode_t mode);