1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2010 Lennart Poettering
14 #include "exit-status.h"
16 #include "mount-setup.h"
17 #include "mount-util.h"
18 #include "path-util.h"
19 #include "process-util.h"
20 #include "signal-util.h"
24 /* Goes through /etc/fstab and remounts all API file systems, applying
25 * options that are in /etc/fstab that systemd might not have
28 int main(int argc
, char *argv
[]) {
29 _cleanup_hashmap_free_free_ Hashmap
*pids
= NULL
;
30 _cleanup_endmntent_
FILE *f
= NULL
;
35 log_error("This program takes no argument.");
39 log_set_target(LOG_TARGET_AUTO
);
40 log_parse_environment();
45 f
= setmntent("/etc/fstab", "re");
47 if (errno
== ENOENT
) {
52 r
= log_error_errno(errno
, "Failed to open /etc/fstab: %m");
56 pids
= hashmap_new(NULL
);
62 while ((me
= getmntent(f
))) {
67 /* Remount the root fs, /usr and all API VFS */
68 if (!mount_point_is_api(me
->mnt_dir
) &&
69 !path_equal(me
->mnt_dir
, "/") &&
70 !path_equal(me
->mnt_dir
, "/usr"))
73 log_debug("Remounting %s", me
->mnt_dir
);
75 r
= safe_fork("(remount)", FORK_RESET_SIGNALS
|FORK_DEATHSIG
|FORK_LOG
, &pid
);
81 execv(MOUNT_PATH
, STRV_MAKE(MOUNT_PATH
, me
->mnt_dir
, "-o", "remount"));
83 log_error_errno(errno
, "Failed to execute " MOUNT_PATH
": %m");
89 s
= strdup(me
->mnt_dir
);
95 k
= hashmap_put(pids
, PID_TO_PTR(pid
), s
);
104 while (!hashmap_isempty(pids
)) {
108 if (waitid(P_ALL
, 0, &si
, WEXITED
) < 0) {
113 r
= log_error_errno(errno
, "waitid() failed: %m");
117 s
= hashmap_remove(pids
, PID_TO_PTR(si
.si_pid
));
119 if (!is_clean_exit(si
.si_code
, si
.si_status
, EXIT_CLEAN_COMMAND
, NULL
)) {
120 if (si
.si_code
== CLD_EXITED
)
121 log_error(MOUNT_PATH
" for %s exited with exit status %i.", s
, si
.si_status
);
123 log_error(MOUNT_PATH
" for %s terminated by signal %s.", s
, signal_to_string(si
.si_status
));
133 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;