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 Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
31 #include "path-util.h"
32 #include "mount-setup.h"
33 #include "exit-status.h"
35 /* Goes through /etc/fstab and remounts all API file systems, applying
36 * options that are in /etc/fstab that systemd might not have
39 int main(int argc, char *argv[]) {
40 int ret = EXIT_FAILURE;
41 _cleanup_endmntent_ FILE *f = NULL;
46 log_error("This program takes no argument.");
50 log_set_target(LOG_TARGET_AUTO);
51 log_parse_environment();
56 f = setmntent("/etc/fstab", "r");
61 log_error_errno(errno, "Failed to open /etc/fstab: %m");
65 pids = hashmap_new(NULL);
67 log_error("Failed to allocate set");
73 while ((me = getmntent(f))) {
78 /* Remount the root fs, /usr and all API VFS */
79 if (!mount_point_is_api(me->mnt_dir) &&
80 !path_equal(me->mnt_dir, "/") &&
81 !path_equal(me->mnt_dir, "/usr"))
84 log_debug("Remounting %s", me->mnt_dir);
88 log_error_errno(errno, "Failed to fork: %m");
94 const char *arguments[5];
97 arguments[0] = "/bin/mount";
98 arguments[1] = me->mnt_dir;
100 arguments[3] = "remount";
103 execv("/bin/mount", (char **) arguments);
105 log_error_errno(errno, "Failed to execute /bin/mount: %m");
111 s = strdup(me->mnt_dir);
119 k = hashmap_put(pids, UINT_TO_PTR(pid), s);
121 log_error_errno(k, "Failed to add PID to set: %m");
127 while (!hashmap_isempty(pids)) {
131 if (waitid(P_ALL, 0, &si, WEXITED) < 0) {
136 log_error_errno(errno, "waitid() failed: %m");
141 s = hashmap_remove(pids, UINT_TO_PTR(si.si_pid));
143 if (!is_clean_exit(si.si_code, si.si_status, NULL)) {
144 if (si.si_code == CLD_EXITED)
145 log_error("/bin/mount for %s exited with exit status %i.", s, si.si_status);
147 log_error("/bin/mount for %s terminated by signal %s.", s, signal_to_string(si.si_status));
159 hashmap_free_free(pids);