summaryrefslogtreecommitdiff
path: root/src/shared/util.c
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/util.c
parent0a498f163ab371ca34b4fe2c1ec8a67e2bb83fe8 (diff)
tmpfiles: add "+" modifier support to b, c, p lines in addition to L
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c40
1 files changed, 40 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);