From 979ef53a268d6f54a309fc5c6015df5d4accbbd5 Mon Sep 17 00:00:00 2001 From: Didier Roche Date: Mon, 24 Nov 2014 09:43:29 +0100 Subject: machine-id-setup: add a machine_id_commit call to commit on disk a transient machine-id If /etc was read only at boot time with an empty /etc/machine-id, the latter will be mounted as a tmpfs and get reset at each boot. If the system becomes rw later, this functionality enables to commit in a race-free manner the transient machine-id to disk. --- src/shared/util.c | 9 +++++++++ src/shared/util.h | 2 ++ 2 files changed, 11 insertions(+) (limited to 'src/shared') diff --git a/src/shared/util.c b/src/shared/util.c index 21651708d5..4fcbab97be 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -3052,6 +3052,15 @@ _pure_ static int is_temporary_fs(struct statfs *s) { F_TYPE_EQUAL(s->f_type, RAMFS_MAGIC); } +int is_fd_on_temporary_fs(int fd) { + struct statfs s; + + if (fstatfs(fd, &s) < 0) + return -errno; + + return is_temporary_fs(&s); +} + int rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev) { struct statfs s; diff --git a/src/shared/util.h b/src/shared/util.h index b53a45da9d..0b7c77b1d4 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -454,6 +454,8 @@ int get_ctty(pid_t, dev_t *_devnr, char **r); int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid); int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid); +int is_fd_on_temporary_fs(int fd); + int rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev); int rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev); int rm_rf(const char *path, bool only_dirs, bool delete_root, bool honour_sticky); -- cgit v1.2.3-54-g00ecf