1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
33 #include "mount-setup.h"
34 #include "exit-status.h"
36 /* Goes through /etc/fstab and remounts all API file systems, applying
37 * options that are in /etc/fstab that systemd might not have
40 int main(int argc, char *argv[]) {
41 int ret = EXIT_FAILURE;
47 log_error("This program takes no argument.");
51 log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
52 log_parse_environment();
55 if (!(f = setmntent("/etc/fstab", "r"))) {
56 log_error("Failed to open /etc/fstab: %m");
60 if (!(pids = hashmap_new(trivial_hash_func, trivial_compare_func))) {
61 log_error("Failed to allocate set");
67 while ((me = getmntent(f))) {
72 if (!mount_point_is_api(me->mnt_dir))
75 log_debug("Remounting %s", me->mnt_dir);
77 if ((pid = fork()) < 0) {
78 log_error("Failed to fork: %m");
84 const char *arguments[5];
87 arguments[0] = "/bin/mount";
88 arguments[1] = me->mnt_dir;
90 arguments[3] = "remount";
93 execv("/bin/mount", (char **) arguments);
95 log_error("Failed to execute /bin/mount: %m");
101 s = strdup(me->mnt_dir);
103 if ((k = hashmap_put(pids, UINT_TO_PTR(pid), s)) < 0) {
104 log_error("Failed to add PID to set: %s", strerror(-k));
110 while (!hashmap_isempty(pids)) {
115 if (waitid(P_ALL, 0, &si, WEXITED) < 0) {
120 log_error("waitid() failed: %m");
125 if ((s = hashmap_remove(pids, UINT_TO_PTR(si.si_pid)))) {
126 if (!is_clean_exit(si.si_code, si.si_status)) {
127 if (si.si_code == CLD_EXITED)
128 log_error("/bin/mount for %s exited with exit status %i.", s, si.si_status);
130 log_error("/bin/mount for %s terminated by signal %s.", s, signal_to_string(si.si_status));
142 hashmap_free_free(pids);