X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fremount-api-vfs.c;h=3e146ebb5c168e4aa57ba7f56b45805119a46fbd;hp=8cdf7e875882009b771f3a5adcbdb68a0e27e406;hb=dd17d38879503f018fdf6bbff822970afcddb6f1;hpb=22f4096ca96acd504ac74e7dfad96f07edb6da51 diff --git a/src/remount-api-vfs.c b/src/remount-api-vfs.c index 8cdf7e875..3e146ebb5 100644 --- a/src/remount-api-vfs.c +++ b/src/remount-api-vfs.c @@ -31,6 +31,7 @@ #include "util.h" #include "set.h" #include "mount-setup.h" +#include "exit-status.h" /* Goes through /etc/fstab and remounts all API file systems, applying * options that are in /etc/fstab that systemd might not have @@ -47,16 +48,20 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - log_set_target(LOG_TARGET_SYSLOG_OR_KMSG); + log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); - if (!(f = setmntent("/etc/fstab", "r"))) { + umask(0022); + + f = setmntent("/etc/fstab", "r"); + if (!f) { log_error("Failed to open /etc/fstab: %m"); goto finish; } - if (!(pids = hashmap_new(trivial_hash_func, trivial_compare_func))) { + pids = hashmap_new(trivial_hash_func, trivial_compare_func); + if (!pids) { log_error("Failed to allocate set"); goto finish; } @@ -73,9 +78,10 @@ int main(int argc, char *argv[]) { log_debug("Remounting %s", me->mnt_dir); - if ((pid = fork()) < 0) { + pid = fork(); + if (pid < 0) { log_error("Failed to fork: %m"); - ret = 1; + ret = EXIT_FAILURE; continue; } @@ -98,8 +104,15 @@ int main(int argc, char *argv[]) { /* Parent */ s = strdup(me->mnt_dir); + if (!s) { + log_error("Out of memory."); + ret = EXIT_FAILURE; + continue; + } + - if ((k = hashmap_put(pids, UINT_TO_PTR(pid), s)) < 0) { + k = hashmap_put(pids, UINT_TO_PTR(pid), s); + if (k < 0) { log_error("Failed to add PID to set: %s", strerror(-k)); ret = EXIT_FAILURE; continue; @@ -121,7 +134,8 @@ int main(int argc, char *argv[]) { break; } - if ((s = hashmap_remove(pids, UINT_TO_PTR(si.si_pid)))) { + s = hashmap_remove(pids, UINT_TO_PTR(si.si_pid)); + if (s) { if (!is_clean_exit(si.si_code, si.si_status)) { if (si.si_code == CLD_EXITED) log_error("/bin/mount for %s exited with exit status %i.", s, si.si_status);