aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-10-26 18:05:03 +0100
committerLennart Poettering <lennart@poettering.net>2015-10-27 13:25:55 +0100
commit0d39fa9c69b97a2ceb156053deef69c0866c2b97 (patch)
treeffab9cf2924c42030cc235cdb1701cfe954958e7 /src
parentutil: remove path_get_parent(), in favour of dirname_malloc() (diff)
downloadsystemd-0d39fa9c69b97a2ceb156053deef69c0866c2b97.tar.gz
systemd-0d39fa9c69b97a2ceb156053deef69c0866c2b97.tar.bz2
systemd-0d39fa9c69b97a2ceb156053deef69c0866c2b97.zip
util-lib: move more file I/O related calls into fileio.[ch]
Diffstat (limited to 'src')
-rw-r--r--src/basic/calendarspec.c1
-rw-r--r--src/basic/copy.c1
-rw-r--r--src/basic/fileio.c302
-rw-r--r--src/basic/fileio.h28
-rw-r--r--src/basic/hostname-util.c1
-rw-r--r--src/basic/time-util.c1
-rw-r--r--src/basic/util.c295
-rw-r--r--src/basic/util.h25
-rw-r--r--src/boot/bootctl.c1
-rw-r--r--src/core/cgroup.c1
-rw-r--r--src/core/dbus-cgroup.c1
-rw-r--r--src/core/dbus-manager.c1
-rw-r--r--src/core/dbus-service.c1
-rw-r--r--src/core/ima-setup.c1
-rw-r--r--src/core/manager.c1
-rw-r--r--src/cryptsetup/cryptsetup-generator.c1
-rw-r--r--src/dbus1-generator/dbus1-generator.c1
-rw-r--r--src/fstab-generator/fstab-generator.c1
-rw-r--r--src/hwdb/hwdb.c3
-rw-r--r--src/import/export-raw.c1
-rw-r--r--src/import/export-tar.c1
-rw-r--r--src/import/import-raw.c1
-rw-r--r--src/import/import-tar.c1
-rw-r--r--src/import/pull-dkr.c1
-rw-r--r--src/import/pull-raw.c1
-rw-r--r--src/import/pull-tar.c1
-rw-r--r--src/journal/catalog.c1
-rw-r--r--src/journal/coredumpctl.c1
-rw-r--r--src/journal/journal-send.c1
-rw-r--r--src/journal/journal-verify.c1
-rw-r--r--src/journal/test-catalog.c1
-rw-r--r--src/journal/test-compress.c1
-rw-r--r--src/journal/test-mmap-cache.c3
-rw-r--r--src/libsystemd-network/sd-lldp.c1
-rw-r--r--src/libsystemd/sd-bus/bus-dump.c3
-rw-r--r--src/libsystemd/sd-bus/bus-introspect.c1
-rw-r--r--src/libsystemd/sd-bus/bus-match.c1
-rw-r--r--src/libsystemd/sd-path/sd-path.c1
-rw-r--r--src/libudev/libudev-monitor.c1
-rw-r--r--src/login/logind-seat.c1
-rw-r--r--src/modules-load/modules-load.c1
-rw-r--r--src/network/networkd-manager.c1
-rw-r--r--src/shared/ask-password-api.c1
-rw-r--r--src/shared/clean-ipc.c1
-rw-r--r--src/shared/machine-pool.c1
-rw-r--r--src/test/test-async.c3
-rw-r--r--src/test/test-fdset.c1
-rw-r--r--src/test/test-terminal-util.c7
-rw-r--r--src/test/test-tmpfiles.c1
-rw-r--r--src/tmpfiles/tmpfiles.c1
-rw-r--r--src/udev/udevadm-hwdb.c1
51 files changed, 382 insertions, 329 deletions
diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c
index 50328e418..62b03a913 100644
--- a/src/basic/calendarspec.c
+++ b/src/basic/calendarspec.c
@@ -24,6 +24,7 @@
#include "string-util.h"
#include "calendarspec.h"
+#include "fileio.h"
#define BITS_WEEKDAYS 127
diff --git a/src/basic/copy.c b/src/basic/copy.c
index 9f274c4d5..4b410a74e 100644
--- a/src/basic/copy.c
+++ b/src/basic/copy.c
@@ -25,6 +25,7 @@
#include "btrfs-util.h"
#include "copy.h"
#include "fd-util.h"
+#include "fileio.h"
#include "io-util.h"
#include "string-util.h"
#include "strv.h"
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index 5d33309ab..b7e447f6b 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -25,6 +25,9 @@
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
+#include "hexdecoct.h"
+#include "path-util.h"
+#include "random-util.h"
#include "string-util.h"
#include "strv.h"
#include "utf8.h"
@@ -54,7 +57,7 @@ static int write_string_file_atomic(const char *fn, const char *line, bool enfor
if (r < 0)
return r;
- fchmod_umask(fileno(f), 0644);
+ (void) fchmod_umask(fileno(f), 0644);
r = write_string_stream(f, line, enforce_newline);
if (r >= 0) {
@@ -63,7 +66,7 @@ static int write_string_file_atomic(const char *fn, const char *line, bool enfor
}
if (r < 0)
- unlink(p);
+ (void) unlink(p);
return r;
}
@@ -848,3 +851,298 @@ int get_proc_field(const char *filename, const char *pattern, const char *termin
*field = f;
return 0;
}
+
+DIR *xopendirat(int fd, const char *name, int flags) {
+ int nfd;
+ DIR *d;
+
+ assert(!(flags & O_CREAT));
+
+ nfd = openat(fd, name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|flags, 0);
+ if (nfd < 0)
+ return NULL;
+
+ d = fdopendir(nfd);
+ if (!d) {
+ safe_close(nfd);
+ return NULL;
+ }
+
+ return d;
+}
+
+static int search_and_fopen_internal(const char *path, const char *mode, const char *root, char **search, FILE **_f) {
+ char **i;
+
+ assert(path);
+ assert(mode);
+ assert(_f);
+
+ if (!path_strv_resolve_uniq(search, root))
+ return -ENOMEM;
+
+ STRV_FOREACH(i, search) {
+ _cleanup_free_ char *p = NULL;
+ FILE *f;
+
+ if (root)
+ p = strjoin(root, *i, "/", path, NULL);
+ else
+ p = strjoin(*i, "/", path, NULL);
+ if (!p)
+ return -ENOMEM;
+
+ f = fopen(p, mode);
+ if (f) {
+ *_f = f;
+ return 0;
+ }
+
+ if (errno != ENOENT)
+ return -errno;
+ }
+
+ return -ENOENT;
+}
+
+int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f) {
+ _cleanup_strv_free_ char **copy = NULL;
+
+ assert(path);
+ assert(mode);
+ assert(_f);
+
+ if (path_is_absolute(path)) {
+ FILE *f;
+
+ f = fopen(path, mode);
+ if (f) {
+ *_f = f;
+ return 0;
+ }
+
+ return -errno;
+ }
+
+ copy = strv_copy((char**) search);
+ if (!copy)
+ return -ENOMEM;
+
+ return search_and_fopen_internal(path, mode, root, copy, _f);
+}
+
+int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f) {
+ _cleanup_strv_free_ char **s = NULL;
+
+ if (path_is_absolute(path)) {
+ FILE *f;
+
+ f = fopen(path, mode);
+ if (f) {
+ *_f = f;
+ return 0;
+ }
+
+ return -errno;
+ }
+
+ s = strv_split_nulstr(search);
+ if (!s)
+ return -ENOMEM;
+
+ return search_and_fopen_internal(path, mode, root, s, _f);
+}
+
+int fopen_temporary(const char *path, FILE **_f, char **_temp_path) {
+ FILE *f;
+ char *t;
+ int r, fd;
+
+ assert(path);
+ assert(_f);
+ assert(_temp_path);
+
+ r = tempfn_xxxxxx(path, NULL, &t);
+ if (r < 0)
+ return r;
+
+ fd = mkostemp_safe(t, O_WRONLY|O_CLOEXEC);
+ if (fd < 0) {
+ free(t);
+ return -errno;
+ }
+
+ f = fdopen(fd, "we");
+ if (!f) {
+ unlink_noerrno(t);
+ free(t);
+ safe_close(fd);
+ return -errno;
+ }
+
+ *_f = f;
+ *_temp_path = t;
+
+ return 0;
+}
+
+int fflush_and_check(FILE *f) {
+ assert(f);
+
+ errno = 0;
+ fflush(f);
+
+ if (ferror(f))
+ return errno ? -errno : -EIO;
+
+ return 0;
+}
+
+/* This is much like like mkostemp() but is subject to umask(). */
+int mkostemp_safe(char *pattern, int flags) {
+ _cleanup_umask_ mode_t u;
+ int fd;
+
+ assert(pattern);
+
+ u = umask(077);
+
+ fd = mkostemp(pattern, flags);
+ if (fd < 0)
+ return -errno;
+
+ return fd;
+}
+
+int open_tmpfile(const char *path, int flags) {
+ char *p;
+ int fd;
+
+ assert(path);
+
+#ifdef O_TMPFILE
+ /* Try O_TMPFILE first, if it is supported */
+ fd = open(path, flags|O_TMPFILE|O_EXCL, S_IRUSR|S_IWUSR);
+ if (fd >= 0)
+ return fd;
+#endif
+
+ /* Fall back to unguessable name + unlinking */
+ p = strjoina(path, "/systemd-tmp-XXXXXX");
+
+ fd = mkostemp_safe(p, flags);
+ if (fd < 0)
+ return fd;
+
+ unlink(p);
+ return fd;
+}
+
+int tempfn_xxxxxx(const char *p, const char *extra, char **ret) {
+ const char *fn;
+ char *t;
+
+ assert(p);
+ assert(ret);
+
+ /*
+ * Turns this:
+ * /foo/bar/waldo
+ *
+ * Into this:
+ * /foo/bar/.#<extra>waldoXXXXXX
+ */
+
+ fn = basename(p);
+ if (!filename_is_valid(fn))
+ return -EINVAL;
+
+ if (extra == NULL)
+ extra = "";
+
+ t = new(char, strlen(p) + 2 + strlen(extra) + 6 + 1);
+ if (!t)
+ return -ENOMEM;
+
+ strcpy(stpcpy(stpcpy(stpcpy(mempcpy(t, p, fn - p), ".#"), extra), fn), "XXXXXX");
+
+ *ret = path_kill_slashes(t);
+ return 0;
+}
+
+int tempfn_random(const char *p, const char *extra, char **ret) {
+ const char *fn;
+ char *t, *x;
+ uint64_t u;
+ unsigned i;
+
+ assert(p);
+ assert(ret);
+
+ /*
+ * Turns this:
+ * /foo/bar/waldo
+ *
+ * Into this:
+ * /foo/bar/.#<extra>waldobaa2a261115984a9
+ */
+
+ fn = basename(p);
+ if (!filename_is_valid(fn))
+ return -EINVAL;
+
+ if (!extra)
+ extra = "";
+
+ t = new(char, strlen(p) + 2 + strlen(extra) + 16 + 1);
+ if (!t)
+ return -ENOMEM;
+
+ x = stpcpy(stpcpy(stpcpy(mempcpy(t, p, fn - p), ".#"), extra), fn);
+
+ u = random_u64();
+ for (i = 0; i < 16; i++) {
+ *(x++) = hexchar(u & 0xF);
+ u >>= 4;
+ }
+
+ *x = 0;
+
+ *ret = path_kill_slashes(t);
+ return 0;
+}
+
+int tempfn_random_child(const char *p, const char *extra, char **ret) {
+ char *t, *x;
+ uint64_t u;
+ unsigned i;
+
+ assert(p);
+ assert(ret);
+
+ /* Turns this:
+ * /foo/bar/waldo
+ * Into this:
+ * /foo/bar/waldo/.#<extra>3c2b6219aa75d7d0
+ */
+
+ if (!extra)
+ extra = "";
+
+ t = new(char, strlen(p) + 3 + strlen(extra) + 16 + 1);
+ if (!t)
+ return -ENOMEM;
+
+ x = stpcpy(stpcpy(stpcpy(t, p), "/.#"), extra);
+
+ u = random_u64();
+ for (i = 0; i < 16; i++) {
+ *(x++) = hexchar(u & 0xF);
+ u >>= 4;
+ }
+
+ *x = 0;
+
+ *ret = path_kill_slashes(t);
+ return 0;
+}
diff --git a/src/basic/fileio.h b/src/basic/fileio.h
index 4998d4d04..fa7f19233 100644
--- a/src/basic/fileio.h
+++ b/src/basic/fileio.h
@@ -20,8 +20,12 @@
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+
+#include <dirent.h>
+#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
+#include <sys/types.h>
#include "macro.h"
@@ -49,3 +53,27 @@ int write_env_file(const char *fname, char **l);
int executable_is_script(const char *path, char **interpreter);
int get_proc_field(const char *filename, const char *pattern, const char *terminator, char **field);
+
+DIR *xopendirat(int dirfd, const char *name, int flags);
+
+int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f);
+int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f);
+
+#define FOREACH_LINE(line, f, on_error) \
+ for (;;) \
+ if (!fgets(line, sizeof(line), f)) { \
+ if (ferror(f)) { \
+ on_error; \
+ } \
+ break; \
+ } else
+
+int fflush_and_check(FILE *f);
+
+int fopen_temporary(const char *path, FILE **_f, char **_temp_path);
+int mkostemp_safe(char *pattern, int flags);
+int open_tmpfile(const char *path, int flags);
+
+int tempfn_xxxxxx(const char *p, const char *extra, char **ret);
+int tempfn_random(const char *p, const char *extra, char **ret);
+int tempfn_random_child(const char *p, const char *extra, char **ret);
diff --git a/src/basic/hostname-util.c b/src/basic/hostname-util.c
index 7d058416e..ea0528c6f 100644
--- a/src/basic/hostname-util.c
+++ b/src/basic/hostname-util.c
@@ -23,6 +23,7 @@
#include <sys/utsname.h>
#include "fd-util.h"
+#include "fileio.h"
#include "hostname-util.h"
#include "string-util.h"
#include "util.h"
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index b348ed420..b7d92cbad 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -24,6 +24,7 @@
#include <sys/timex.h>
#include "fd-util.h"
+#include "fileio.h"
#include "path-util.h"
#include "string-util.h"
#include "strv.h"
diff --git a/src/basic/util.c b/src/basic/util.c
index f403dca10..25ba59505 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -636,25 +636,6 @@ int null_or_empty_fd(int fd) {
return null_or_empty(&st);
}
-DIR *xopendirat(int fd, const char *name, int flags) {
- int nfd;
- DIR *d;
-
- assert(!(flags & O_CREAT));
-
- nfd = openat(fd, name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|flags, 0);
- if (nfd < 0)
- return NULL;
-
- d = fdopendir(nfd);
- if (!d) {
- safe_close(nfd);
- return NULL;
- }
-
- return d;
-}
-
static char *tag_to_udev_node(const char *tagvalue, const char *by) {
_cleanup_free_ char *t = NULL, *u = NULL;
size_t enc_len;
@@ -864,39 +845,6 @@ bool plymouth_running(void) {
return access("/run/plymouth/pid", F_OK) >= 0;
}
-int fopen_temporary(const char *path, FILE **_f, char **_temp_path) {
- FILE *f;
- char *t;
- int r, fd;
-
- assert(path);
- assert(_f);
- assert(_temp_path);
-
- r = tempfn_xxxxxx(path, NULL, &t);
- if (r < 0)
- return r;
-
- fd = mkostemp_safe(t, O_WRONLY|O_CLOEXEC);
- if (fd < 0) {
- free(t);
- return -errno;
- }
-
- f = fdopen(fd, "we");
- if (!f) {
- unlink_noerrno(t);
- free(t);
- safe_close(fd);
- return -errno;
- }
-
- *_f = f;
- *_temp_path = t;
-
- return 0;
-}
-
int symlink_atomic(const char *from, const char *to) {
_cleanup_free_ char *t = NULL;
int r;
@@ -1782,88 +1730,6 @@ int on_ac_power(void) {
return found_online || !found_offline;
}
-static int search_and_fopen_internal(const char *path, const char *mode, const char *root, char **search, FILE **_f) {
- char **i;
-
- assert(path);
- assert(mode);
- assert(_f);
-
- if (!path_strv_resolve_uniq(search, root))
- return -ENOMEM;
-
- STRV_FOREACH(i, search) {
- _cleanup_free_ char *p = NULL;
- FILE *f;
-
- if (root)
- p = strjoin(root, *i, "/", path, NULL);
- else
- p = strjoin(*i, "/", path, NULL);
- if (!p)
- return -ENOMEM;
-
- f = fopen(p, mode);
- if (f) {
- *_f = f;
- return 0;
- }
-
- if (errno != ENOENT)
- return -errno;
- }
-
- return -ENOENT;
-}
-
-int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f) {
- _cleanup_strv_free_ char **copy = NULL;
-
- assert(path);
- assert(mode);
- assert(_f);
-
- if (path_is_absolute(path)) {
- FILE *f;
-
- f = fopen(path, mode);
- if (f) {
- *_f = f;
- return 0;
- }
-
- return -errno;
- }
-
- copy = strv_copy((char**) search);
- if (!copy)
- return -ENOMEM;
-
- return search_and_fopen_internal(path, mode, root, copy, _f);
-}
-
-int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f) {
- _cleanup_strv_free_ char **s = NULL;
-
- if (path_is_absolute(path)) {
- FILE *f;
-
- f = fopen(path, mode);
- if (f) {
- *_f = f;
- return 0;
- }
-
- return -errno;
- }
-
- s = strv_split_nulstr(search);
- if (!s)
- return -ENOMEM;
-
- return search_and_fopen_internal(path, mode, root, s, _f);
-}
-
void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) {
size_t a, newalloc;
void *q;
@@ -2213,46 +2079,6 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int
return reset_uid_gid();
}
-/* This is much like like mkostemp() but is subject to umask(). */
-int mkostemp_safe(char *pattern, int flags) {
- _cleanup_umask_ mode_t u;
- int fd;
-
- assert(pattern);
-
- u = umask(077);
-
- fd = mkostemp(pattern, flags);
- if (fd < 0)
- return -errno;
-
- return fd;
-}
-
-int open_tmpfile(const char *path, int flags) {
- char *p;
- int fd;
-
- assert(path);
-
-#ifdef O_TMPFILE
- /* Try O_TMPFILE first, if it is supported */
- fd = open(path, flags|O_TMPFILE|O_EXCL, S_IRUSR|S_IWUSR);
- if (fd >= 0)
- return fd;
-#endif
-
- /* Fall back to unguessable name + unlinking */
- p = strjoina(path, "/systemd-tmp-XXXXXX");
-
- fd = mkostemp_safe(p, flags);
- if (fd < 0)
- return fd;
-
- unlink(p);
- return fd;
-}
-
int fd_warn_permissions(const char *path, int fd) {
struct stat st;
@@ -2599,127 +2425,6 @@ int bind_remount_recursive(const char *prefix, bool ro) {
}
}
-int fflush_and_check(FILE *f) {
- assert(f);
-
- errno = 0;
- fflush(f);
-
- if (ferror(f))
- return errno ? -errno : -EIO;
-
- return 0;
-}
-
-int tempfn_xxxxxx(const char *p, const char *extra, char **ret) {
- const char *fn;
- char *t;
-
- assert(p);
- assert(ret);
-
- /*
- * Turns this:
- * /foo/bar/waldo
- *
- * Into this:
- * /foo/bar/.#<extra>waldoXXXXXX
- */
-
- fn = basename(p);
- if (!filename_is_valid(fn))
- return -EINVAL;
-
- if (extra == NULL)
- extra = "";
-
- t = new(char, strlen(p) + 2 + strlen(extra) + 6 + 1);
- if (!t)
- return -ENOMEM;
-
- strcpy(stpcpy(stpcpy(stpcpy(mempcpy(t, p, fn - p), ".#"), extra), fn), "XXXXXX");
-
- *ret = path_kill_slashes(t);
- return 0;
-}
-
-int tempfn_random(const char *p, const char *extra, char **ret) {
- const char *fn;
- char *t, *x;
- uint64_t u;
- unsigned i;
-
- assert(p);
- assert(ret);
-
- /*
- * Turns this:
- * /foo/bar/waldo
- *
- * Into this:
- * /foo/bar/.#<extra>waldobaa2a261115984a9
- */
-
- fn = basename(p);
- if (!filename_is_valid(fn))
- return -EINVAL;
-
- if (!extra)
- extra = "";
-
- t = new(char, strlen(p) + 2 + strlen(extra) + 16 + 1);
- if (!t)
- return -ENOMEM;
-
- x = stpcpy(stpcpy(stpcpy(mempcpy(t, p, fn - p), ".#"), extra), fn);
-
- u = random_u64();
- for (i = 0; i < 16; i++) {
- *(x++) = hexchar(u & 0xF);
- u >>= 4;
- }
-
- *x = 0;
-
- *ret = path_kill_slashes(t);
- return 0;
-}
-
-int tempfn_random_child(const char *p, const char *extra, char **ret) {
- char *t, *x;
- uint64_t u;
- unsigned i;
-
- assert(p);
- assert(ret);
-
- /* Turns this:
- * /foo/bar/waldo
- * Into this:
- * /foo/bar/waldo/.#<extra>3c2b6219aa75d7d0
- */
-
- if (!extra)
- extra = "";
-
- t = new(char, strlen(p) + 3 + strlen(extra) + 16 + 1);
- if (!t)
- return -ENOMEM;
-
- x = stpcpy(stpcpy(stpcpy(t, p), "/.#"), extra);
-
- u = random_u64();
- for (i = 0; i < 16; i++) {
- *(x++) = hexchar(u & 0xF);
- u >>= 4;
- }
-
- *x = 0;
-
- *ret = path_kill_slashes(t);
- return 0;
-}
-
int take_password_lock(const char *root) {
struct flock flock = {
diff --git a/src/basic/util.h b/src/basic/util.h
index ec95c5313..9393140c7 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -158,8 +158,6 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
bool fstype_is_network(const char *fstype);
-int fopen_temporary(const char *path, FILE **_f, char **_temp_path);
-
bool is_device_path(const char *path);
int dir_is_empty(const char *path);
@@ -201,8 +199,6 @@ bool null_or_empty(struct stat *st) _pure_;
int null_or_empty_path(const char *fn);
int null_or_empty_fd(int fd);
-DIR *xopendirat(int dirfd, const char *name, int flags);
-
char *fstab_node_to_udev_node(const char *p);
void execute_directories(const char* const* directories, usec_t timeout, char *argv[]);
@@ -349,18 +345,6 @@ const char *draw_special_char(DrawSpecialChar ch);
int on_ac_power(void);
-int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f);
-int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f);
-
-#define FOREACH_LINE(line, f, on_error) \
- for (;;) \
- if (!fgets(line, sizeof(line), f)) { \
- if (ferror(f)) { \
- on_error; \
- } \
- break; \
- } else
-
#define FOREACH_DIRENT(de, d, on_error) \
for (errno = 0, de = readdir(d);; errno = 0, de = readdir(d)) \
if (!de) { \
@@ -521,9 +505,6 @@ int container_get_leader(const char *machine, pid_t *pid);
int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd);
int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd);
-int mkostemp_safe(char *pattern, int flags);
-int open_tmpfile(const char *path, int flags);
-
int fd_warn_permissions(const char *path, int fd);
#ifndef PERSONALITY_INVALID
@@ -550,12 +531,6 @@ int umount_recursive(const char *target, int flags);
int bind_remount_recursive(const char *prefix, bool ro);
-int fflush_and_check(FILE *f);
-
-int tempfn_xxxxxx(const char *p, const char *extra, char **ret);
-int tempfn_random(const char *p, const char *extra, char **ret);
-int tempfn_random_child(const char *p, const char *extra, char **ret);
-
int take_password_lock(const char *root);
int is_symlink(const char *path);
diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c
index a167f8086..7e06abd3b 100644
--- a/src/boot/bootctl.c
+++ b/src/boot/bootctl.c
@@ -40,6 +40,7 @@
#include "blkid-util.h"
#include "efivars.h"
#include "fd-util.h"
+#include "fileio.h"
#include "rm-rf.h"
#include "string-util.h"
#include "util.h"
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index a33eaa8d4..6ef0580fa 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -25,6 +25,7 @@
#include "cgroup-util.h"
#include "cgroup.h"
#include "fd-util.h"
+#include "fileio.h"
#include "parse-util.h"
#include "path-util.h"
#include "process-util.h"
diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
index 6a43be873..f424909b4 100644
--- a/src/core/dbus-cgroup.c
+++ b/src/core/dbus-cgroup.c
@@ -24,6 +24,7 @@
#include "cgroup.h"
#include "dbus-cgroup.h"
#include "fd-util.h"
+#include "fileio.h"
#include "path-util.h"
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_cgroup_device_policy, cgroup_device_policy, CGroupDevicePolicy);
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 1ef259ec7..77a64dfd5 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -35,6 +35,7 @@
#include "dbus.h"
#include "env-util.h"
#include "fd-util.h"
+#include "fileio.h"
#include "formats-util.h"
#include "install.h"
#include "log.h"
diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c
index 22b8690c5..91cdeb1f3 100644
--- a/src/core/dbus-service.c
+++ b/src/core/dbus-service.c
@@ -26,6 +26,7 @@
#include "dbus-kill.h"
#include "dbus-service.h"
#include "fd-util.h"
+#include "fileio.h"
#include "path-util.h"
#include "service.h"
#include "string-util.h"
diff --git a/src/core/ima-setup.c b/src/core/ima-setup.c
index 0c0982b0b..9572fa17d 100644
--- a/src/core/ima-setup.c
+++ b/src/core/ima-setup.c
@@ -25,6 +25,7 @@
#include <errno.h>
#include "fd-util.h"
+#include "fileio.h"
#include "ima-setup.h"
#include "log.h"
#include "util.h"
diff --git a/src/core/manager.c b/src/core/manager.c
index 9ad8a136a..589501519 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -54,6 +54,7 @@
#include "escape.h"
#include "exit-status.h"
#include "fd-util.h"
+#include "fileio.h"
#include "hashmap.h"
#include "io-util.h"
#include "locale-setup.h"
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index 51a2c6dfd..768d59c8d 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -23,6 +23,7 @@
#include "dropin.h"
#include "fd-util.h"
+#include "fileio.h"
#include "fstab-util.h"
#include "generator.h"
#include "hashmap.h"
diff --git a/src/dbus1-generator/dbus1-generator.c b/src/dbus1-generator/dbus1-generator.c
index 8dd75f332..b9683a7ee 100644
--- a/src/dbus1-generator/dbus1-generator.c
+++ b/src/dbus1-generator/dbus1-generator.c
@@ -24,6 +24,7 @@
#include "cgroup-util.h"
#include "conf-parser.h"
#include "fd-util.h"
+#include "fileio.h"
#include "mkdir.h"
#include "special.h"
#include "unit-name.h"
diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c
index 18baf6cc7..732b3d170 100644
--- a/src/fstab-generator/fstab-generator.c
+++ b/src/fstab-generator/fstab-generator.c
@@ -26,6 +26,7 @@
#include <unistd.h>
#include "fd-util.h"
+#include "fileio.h"
#include "fstab-util.h"
#include "generator.h"
#include "log.h"
diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c
index 3b800e99d..b4118828a 100644
--- a/src/hwdb/hwdb.c
+++ b/src/hwdb/hwdb.c
@@ -23,6 +23,8 @@
#include <string.h>
#include "conf-files.h"
+#include "fd-util.h"
+#include "fileio.h"
#include "hwdb-internal.h"
#include "hwdb-util.h"
#include "mkdir.h"
@@ -31,7 +33,6 @@
#include "strv.h"
#include "util.h"
#include "verbs.h"
-#include "fd-util.h"
/*
* Generic udev properties, key/value database based on modalias strings.
diff --git a/src/import/export-raw.c b/src/import/export-raw.c
index 24c0ec930..85e781a30 100644
--- a/src/import/export-raw.c
+++ b/src/import/export-raw.c
@@ -29,6 +29,7 @@
#include "copy.h"
#include "export-raw.h"
#include "fd-util.h"
+#include "fileio.h"
#include "import-common.h"
#include "ratelimit.h"
#include "string-util.h"
diff --git a/src/import/export-tar.c b/src/import/export-tar.c
index aa9b7f1a9..38e659a51 100644
--- a/src/import/export-tar.c
+++ b/src/import/export-tar.c
@@ -24,6 +24,7 @@
#include "btrfs-util.h"
#include "export-tar.h"
#include "fd-util.h"
+#include "fileio.h"
#include "import-common.h"
#include "process-util.h"
#include "ratelimit.h"
diff --git a/src/import/import-raw.c b/src/import/import-raw.c
index a34f30abf..d94d8ab4a 100644
--- a/src/import/import-raw.c
+++ b/src/import/import-raw.c
@@ -27,6 +27,7 @@
#include "btrfs-util.h"
#include "copy.h"
#include "fd-util.h"
+#include "fileio.h"
#include "hostname-util.h"
#include "import-common.h"
#include "import-compress.h"
diff --git a/src/import/import-tar.c b/src/import/import-tar.c
index 9aade0f43..d88eae197 100644
--- a/src/import/import-tar.c
+++ b/src/import/import-tar.c
@@ -27,6 +27,7 @@
#include "btrfs-util.h"
#include "copy.h"
#include "fd-util.h"
+#include "fileio.h"
#include "hostname-util.h"
#include "import-common.h"
#include "import-compress.h"
diff --git a/src/import/pull-dkr.c b/src/import/pull-dkr.c
index 448dbafa9..700462bfd 100644
--- a/src/import/pull-dkr.c
+++ b/src/import/pull-dkr.c
@@ -28,6 +28,7 @@
#include "btrfs-util.h"
#include "curl-util.h"
#include "fd-util.h"
+#include "fileio.h"
#include "hostname-util.h"
#include "import-common.h"
#include "import-util.h"
diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c
index 848a4fcd4..4d0ac770a 100644
--- a/src/import/pull-raw.c
+++ b/src/import/pull-raw.c
@@ -29,6 +29,7 @@
#include "copy.h"
#include "curl-util.h"
#include "fd-util.h"
+#include "fileio.h"
#include "hostname-util.h"
#include "import-common.h"
#include "import-util.h"
diff --git a/src/import/pull-tar.c b/src/import/pull-tar.c
index 3540bbff4..3e21d7215 100644
--- a/src/import/pull-tar.c
+++ b/src/import/pull-tar.c
@@ -28,6 +28,7 @@
#include "copy.h"
#include "curl-util.h"
#include "fd-util.h"
+#include "fileio.h"
#include "hostname-util.h"
#include "import-common.h"
#include "import-util.h"
diff --git a/src/journal/catalog.c b/src/journal/catalog.c
index fe3975b7b..72d2bedc2 100644
--- a/src/journal/catalog.c
+++ b/src/journal/catalog.c
@@ -32,6 +32,7 @@
#include "catalog.h"
#include "conf-files.h"
#include "fd-util.h"
+#include "fileio.h"
#include "hashmap.h"
#include "log.h"
#include "mkdir.h"
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index fecccd4eb..07ca8dde0 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -30,6 +30,7 @@
#include "compress.h"
#include "fd-util.h"
+#include "fileio.h"
#include "journal-internal.h"
#include "log.h"
#include "macro.h"
diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c
index f388c30d2..dddd5703f 100644
--- a/src/journal/journal-send.c
+++ b/src/journal/journal-send.c
@@ -32,6 +32,7 @@
#include "sd-journal.h"
#include "fd-util.h"
+#include "fileio.h"
#include "io-util.h"
#include "memfd-util.h"
#include "socket-util.h"
diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c
index de4f73a47..5d000aedb 100644
--- a/src/journal/journal-verify.c
+++ b/src/journal/journal-verify.c
@@ -26,6 +26,7 @@
#include "compress.h"
#include "fd-util.h"
+#include "fileio.h"
#include "journal-authenticate.h"
#include "journal-def.h"
#include "journal-file.h"
diff --git a/src/journal/test-catalog.c b/src/journal/test-catalog.c
index 72c1f60f0..c942df46a 100644
--- a/src/journal/test-catalog.c
+++ b/src/journal/test-catalog.c
@@ -29,6 +29,7 @@
#include "catalog.h"
#include "fd-util.h"
+#include "fileio.h"
#include "log.h"
#include "macro.h"
#include "string-util.h"
diff --git a/src/journal/test-compress.c b/src/journal/test-compress.c
index e562fa194..db4fa1555 100644
--- a/src/journal/test-compress.c
+++ b/src/journal/test-compress.c
@@ -19,6 +19,7 @@
#include "compress.h"
#include "fd-util.h"
+#include "fileio.h"
#include "macro.h"
#include "random-util.h"
#include "util.h"
diff --git a/src/journal/test-mmap-cache.c b/src/journal/test-mmap-cache.c
index ac1239acc..fdd48e531 100644
--- a/src/journal/test-mmap-cache.c
+++ b/src/journal/test-mmap-cache.c
@@ -19,12 +19,13 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include <fcntl.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
-#include <fcntl.h>
#include "fd-util.h"
+#include "fileio.h"
#include "macro.h"
#include "mmap-cache.h"
#include "util.h"
diff --git a/src/libsystemd-network/sd-lldp.c b/src/libsystemd-network/sd-lldp.c
index b2b85e56e..bc06f4838 100644
--- a/src/libsystemd-network/sd-lldp.c
+++ b/src/libsystemd-network/sd-lldp.c
@@ -25,6 +25,7 @@
#include "sd-lldp.h"
#include "fd-util.h"
+#include "fileio.h"
#include "hashmap.h"
#include "lldp-internal.h"
#include "lldp-port.h"
diff --git a/src/libsystemd/sd-bus/bus-dump.c b/src/libsystemd/sd-bus/bus-dump.c
index cd7fcc7c8..9ddd05907 100644
--- a/src/libsystemd/sd-bus/bus-dump.c
+++ b/src/libsystemd/sd-bus/bus-dump.c
@@ -19,18 +19,19 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include "bus-dump.h"
#include "bus-internal.h"
#include "bus-message.h"
#include "bus-type.h"
#include "cap-list.h"
#include "capability.h"
+#include "fileio.h"
#include "formats-util.h"
#include "macro.h"
#include "string-util.h"
#include "strv.h"
#include "terminal-util.h"
#include "util.h"
-#include "bus-dump.h"
static char *indent(unsigned level, unsigned flags) {
char *p;
diff --git a/src/libsystemd/sd-bus/bus-introspect.c b/src/libsystemd/sd-bus/bus-introspect.c
index f5a888533..a90536bac 100644
--- a/src/libsystemd/sd-bus/bus-introspect.c
+++ b/src/libsystemd/sd-bus/bus-introspect.c
@@ -24,6 +24,7 @@
#include "bus-protocol.h"
#include "bus-signature.h"
#include "fd-util.h"
+#include "fileio.h"
#include "string-util.h"
#include "util.h"
diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c
index fca3ebd39..6a37f22c1 100644
--- a/src/libsystemd/sd-bus/bus-match.c
+++ b/src/libsystemd/sd-bus/bus-match.c
@@ -24,6 +24,7 @@
#include "bus-message.h"
#include "bus-util.h"
#include "fd-util.h"
+#include "fileio.h"
#include "hexdecoct.h"
#include "string-util.h"
#include "strv.h"
diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c
index 8e3eeb15d..c1d42e96e 100644
--- a/src/libsystemd/sd-path/sd-path.c
+++ b/src/libsystemd/sd-path/sd-path.c
@@ -21,6 +21,7 @@
#include "architecture.h"
#include "fd-util.h"
+#include "fileio.h"
#include "missing.h"
#include "path-util.h"
#include "string-util.h"
diff --git a/src/libudev/libudev-monitor.c b/src/libudev/libudev-monitor.c
index 5590aec2b..0059c09e7 100644
--- a/src/libudev/libudev-monitor.c
+++ b/src/libudev/libudev-monitor.c
@@ -31,6 +31,7 @@
#include "libudev.h"
#include "fd-util.h"
+#include "fileio.h"
#include "formats-util.h"
#include "libudev-private.h"
#include "missing.h"
diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c
index 2566894d0..2dcf8ddc6 100644
--- a/src/login/logind-seat.c
+++ b/src/login/logind-seat.c
@@ -27,6 +27,7 @@
#include "sd-messages.h"
#include "fd-util.h"
+#include "fileio.h"
#include "formats-util.h"
#include "logind-acl.h"
#include "logind-seat.h"
diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c
index 34bd65cb1..5627e6393 100644
--- a/src/modules-load/modules-load.c
+++ b/src/modules-load/modules-load.c
@@ -28,6 +28,7 @@
#include "conf-files.h"
#include "fd-util.h"
+#include "fileio.h"
#include "log.h"
#include "string-util.h"
#include "strv.h"
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index febfe2ff8..af243c9a7 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -29,6 +29,7 @@
#include "conf-parser.h"
#include "def.h"
#include "fd-util.h"
+#include "fileio.h"
#include "libudev-private.h"
#include "local-addresses.h"
#include "netlink-util.h"
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c
index 15203d21e..9e8025d61 100644
--- a/src/shared/ask-password-api.c
+++ b/src/shared/ask-password-api.c
@@ -34,6 +34,7 @@
#include "ask-password-api.h"
#include "fd-util.h"
+#include "fileio.h"
#include "formats-util.h"
#include "io-util.h"
#include "missing.h"
diff --git a/src/shared/clean-ipc.c b/src/shared/clean-ipc.c
index fe3187384..2be1bc3fc 100644
--- a/src/shared/clean-ipc.c
+++ b/src/shared/clean-ipc.c
@@ -30,6 +30,7 @@
#include "clean-ipc.h"
#include "fd-util.h"
+#include "fileio.h"
#include "formats-util.h"
#include "string-util.h"
#include "strv.h"
diff --git a/src/shared/machine-pool.c b/src/shared/machine-pool.c
index c576242b5..6d726a687 100644
--- a/src/shared/machine-pool.c
+++ b/src/shared/machine-pool.c
@@ -26,6 +26,7 @@
#include "btrfs-util.h"
#include "fd-util.h"
+#include "fileio.h"
#include "lockfile-util.h"
#include "machine-pool.h"
#include "mkdir.h"
diff --git a/src/test/test-async.c b/src/test/test-async.c
index abd36d693..ada6d67c4 100644
--- a/src/test/test-async.c
+++ b/src/test/test-async.c
@@ -20,8 +20,9 @@
#include <unistd.h>
#include "async.h"
-#include "util.h"
+#include "fileio.h"
#include "macro.h"
+#include "util.h"
static bool test_async = false;
diff --git a/src/test/test-fdset.c b/src/test/test-fdset.c
index 96d5e3817..282aab124 100644
--- a/src/test/test-fdset.c
+++ b/src/test/test-fdset.c
@@ -22,6 +22,7 @@
#include "fd-util.h"
#include "fdset.h"
+#include "fileio.h"
#include "macro.h"
#include "util.h"
diff --git a/src/test/test-terminal-util.c b/src/test/test-terminal-util.c
index a41de5971..e940b5a20 100644
--- a/src/test/test-terminal-util.c
+++ b/src/test/test-terminal-util.c
@@ -21,11 +21,12 @@
#include <stdio.h>
#include <stdbool.h>
-#include "terminal-util.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "log.h"
#include "macro.h"
+#include "terminal-util.h"
#include "util.h"
-#include "log.h"
-#include "fd-util.h"
static void test_default_term_for_tty(void) {
puts(default_term_for_tty("/dev/tty23"));
diff --git a/src/test/test-tmpfiles.c b/src/test/test-tmpfiles.c
index 6aa9cc847..683fbe217 100644
--- a/src/test/test-tmpfiles.c
+++ b/src/test/test-tmpfiles.c
@@ -25,6 +25,7 @@
#include <unistd.h>
#include "fd-util.h"
+#include "fileio.h"
#include "formats-util.h"
#include "string-util.h"
#include "util.h"
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 57cca17e8..85a2d6c2f 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -45,6 +45,7 @@
#include "copy.h"
#include "escape.h"
#include "fd-util.h"
+#include "fileio.h"
#include "formats-util.h"
#include "io-util.h"
#include "label.h"
diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c
index f9509ad64..69aff7b57 100644
--- a/src/udev/udevadm-hwdb.c
+++ b/src/udev/udevadm-hwdb.c
@@ -23,6 +23,7 @@
#include <string.h>
#include "conf-files.h"
+#include "fileio.h"
#include "hwdb-internal.h"
#include "hwdb-util.h"
#include "strbuf.h"