summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index cdd9a48866..27fc9594cd 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -6108,3 +6108,25 @@ int getpeersec(int fd, char **ret) {
*ret = s;
return 0;
}
+
+int open_tmpfile(const char *path, int flags) {
+ int fd;
+ char *p;
+
+#ifdef O_TMPFILE
+ fd = open(path, flags|O_TMPFILE, S_IRUSR|S_IWUSR);
+ if (fd >= 0)
+ return fd;
+#endif
+ p = strappenda(path, "/systemd-tmp-XXXXXX");
+
+ RUN_WITH_UMASK(0077) {
+ fd = mkostemp(p, O_RDWR|O_CLOEXEC);
+ }
+
+ if (fd < 0)
+ return -errno;
+
+ unlink(p);
+ return fd;
+}