X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fremount-api-vfs.c;h=6cb77c1d1a1ef02e9ab715ebdbf4de50c8729f20;hb=90ccc3fca7e53a60a9e67b9d5812e1d4a27fc07d;hp=d51a584f2f7ad24aeac52633bd6f06f36a959452;hpb=449ddb2d23a63ca4c8cd70d13a070fba87c1fb30;p=elogind.git diff --git a/src/remount-api-vfs.c b/src/remount-api-vfs.c index d51a584f2..6cb77c1d1 100644 --- a/src/remount-api-vfs.c +++ b/src/remount-api-vfs.c @@ -6,16 +6,16 @@ Copyright 2010 Lennart Poettering systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. systemd is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . ***/ @@ -31,37 +31,42 @@ #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 * respected */ int main(int argc, char *argv[]) { - int ret = 1; + int ret = EXIT_FAILURE; FILE *f = NULL; struct mntent* me; Hashmap *pids = NULL; if (argc > 1) { log_error("This program takes no argument."); - return 1; + 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; } - ret = 0; + ret = EXIT_SUCCESS; while ((me = getmntent(f))) { pid_t pid; @@ -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; } @@ -92,16 +98,23 @@ int main(int argc, char *argv[]) { execv("/bin/mount", (char **) arguments); log_error("Failed to execute /bin/mount: %m"); - _exit(1); + _exit(EXIT_FAILURE); } /* 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 = 1; + ret = EXIT_FAILURE; continue; } } @@ -117,18 +130,19 @@ int main(int argc, char *argv[]) { continue; log_error("waitid() failed: %m"); - ret = 1; + ret = EXIT_FAILURE; 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); else log_error("/bin/mount for %s terminated by signal %s.", s, signal_to_string(si.si_status)); - ret = 1; + ret = EXIT_FAILURE; } free(s);