1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
11 #include <sys/prctl.h>
16 #include "exit-status.h"
18 #include "mount-setup.h"
19 #include "mount-util.h"
20 #include "path-util.h"
21 #include "process-util.h"
22 #include "signal-util.h"
26 /* Goes through /etc/fstab and remounts all API file systems, applying
27 * options that are in /etc/fstab that systemd might not have
30 int main(int argc
, char *argv
[]) {
31 _cleanup_hashmap_free_free_ Hashmap
*pids
= NULL
;
32 _cleanup_endmntent_
FILE *f
= NULL
;
37 log_error("This program takes no argument.");
41 log_set_target(LOG_TARGET_AUTO
);
42 log_parse_environment();
47 f
= setmntent("/etc/fstab", "re");
49 if (errno
== ENOENT
) {
54 r
= log_error_errno(errno
, "Failed to open /etc/fstab: %m");
58 pids
= hashmap_new(NULL
);
64 while ((me
= getmntent(f
))) {
69 /* Remount the root fs, /usr and all API VFS */
70 if (!mount_point_is_api(me
->mnt_dir
) &&
71 !path_equal(me
->mnt_dir
, "/") &&
72 !path_equal(me
->mnt_dir
, "/usr"))
75 log_debug("Remounting %s", me
->mnt_dir
);
77 r
= safe_fork("(remount)", FORK_RESET_SIGNALS
|FORK_DEATHSIG
|FORK_LOG
, &pid
);
83 execv(MOUNT_PATH
, STRV_MAKE(MOUNT_PATH
, me
->mnt_dir
, "-o", "remount"));
85 log_error_errno(errno
, "Failed to execute " MOUNT_PATH
": %m");
91 s
= strdup(me
->mnt_dir
);
97 k
= hashmap_put(pids
, PID_TO_PTR(pid
), s
);
106 while (!hashmap_isempty(pids
)) {
110 if (waitid(P_ALL
, 0, &si
, WEXITED
) < 0) {
115 r
= log_error_errno(errno
, "waitid() failed: %m");
119 s
= hashmap_remove(pids
, PID_TO_PTR(si
.si_pid
));
121 if (!is_clean_exit(si
.si_code
, si
.si_status
, EXIT_CLEAN_COMMAND
, NULL
)) {
122 if (si
.si_code
== CLD_EXITED
)
123 log_error(MOUNT_PATH
" for %s exited with exit status %i.", s
, si
.si_status
);
125 log_error(MOUNT_PATH
" for %s terminated by signal %s.", s
, signal_to_string(si
.si_status
));
135 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;