diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-11-23 19:41:11 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-12-18 14:47:06 +0100 |
commit | 58b86fdf1dcb47676c9e82d38546b779fa9cb66b (patch) | |
tree | 87fb470fe946fb89090827c3eccb724cadd5b351 | |
parent | remount-fs: use PATH_IN_SET() at one more place (diff) | |
download | systemd-58b86fdf1dcb47676c9e82d38546b779fa9cb66b.tar.gz systemd-58b86fdf1dcb47676c9e82d38546b779fa9cb66b.tar.bz2 systemd-58b86fdf1dcb47676c9e82d38546b779fa9cb66b.zip |
remount-fs: split code for tracking PIDs in hashmap
Just some refactoring, no change in behaviour.
-rw-r--r-- | src/remount-fs/remount-fs.c | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c index bfc6ca67a..88e2b34ac 100644 --- a/src/remount-fs/remount-fs.c +++ b/src/remount-fs/remount-fs.c @@ -19,9 +19,32 @@ #include "strv.h" #include "util.h" -/* Goes through /etc/fstab and remounts all API file systems, applying - * options that are in /etc/fstab that systemd might not have - * respected */ +/* Goes through /etc/fstab and remounts all API file systems, applying options that are in /etc/fstab that systemd + * might not have respected */ + +static int track_pid(Hashmap **h, const char *path, pid_t pid) { + _cleanup_free_ char *c = NULL; + int r; + + assert(h); + assert(path); + assert(pid_is_valid(pid)); + + r = hashmap_ensure_allocated(h, NULL); + if (r < 0) + return log_oom(); + + c = strdup(path); + if (!c) + return log_oom(); + + r = hashmap_put(*h, PID_TO_PTR(pid), c); + if (r < 0) + return log_oom(); + + TAKE_PTR(c); + return 0; +} static int run(int argc, char *argv[]) { _cleanup_hashmap_free_free_ Hashmap *pids = NULL; @@ -45,14 +68,8 @@ static int run(int argc, char *argv[]) { return log_error_errno(errno, "Failed to open /etc/fstab: %m"); } - pids = hashmap_new(NULL); - if (!pids) - return log_oom(); - while ((me = getmntent(f))) { - _cleanup_free_ char *s = NULL; pid_t pid; - int k; /* Remount the root fs, /usr and all API VFS */ if (!mount_point_is_api(me->mnt_dir) && @@ -74,15 +91,9 @@ static int run(int argc, char *argv[]) { } /* Parent */ - - s = strdup(me->mnt_dir); - if (!s) - return log_oom(); - - k = hashmap_put(pids, PID_TO_PTR(pid), s); - if (k < 0) - return log_oom(); - TAKE_PTR(s); + r = track_pid(&pids, me->mnt_dir, pid); + if (r < 0) + return r; } r = 0; |