1 /* SPDX-License-Identifier: LGPL-2.1+ */
11 #include "exit-status.h"
13 #include "mount-setup.h"
14 #include "mount-util.h"
15 #include "path-util.h"
16 #include "process-util.h"
17 #include "signal-util.h"
21 /* Goes through /etc/fstab and remounts all API file systems, applying
22 * options that are in /etc/fstab that systemd might not have
25 int main(int argc
, char *argv
[]) {
26 _cleanup_hashmap_free_free_ Hashmap
*pids
= NULL
;
27 _cleanup_endmntent_
FILE *f
= NULL
;
32 log_error("This program takes no argument.");
36 log_set_target(LOG_TARGET_AUTO
);
37 log_parse_environment();
42 f
= setmntent("/etc/fstab", "re");
44 if (errno
== ENOENT
) {
49 r
= log_error_errno(errno
, "Failed to open /etc/fstab: %m");
53 pids
= hashmap_new(NULL
);
59 while ((me
= getmntent(f
))) {
64 /* Remount the root fs, /usr and all API VFS */
65 if (!mount_point_is_api(me
->mnt_dir
) &&
66 !path_equal(me
->mnt_dir
, "/") &&
67 !path_equal(me
->mnt_dir
, "/usr"))
70 log_debug("Remounting %s", me
->mnt_dir
);
72 r
= safe_fork("(remount)", FORK_RESET_SIGNALS
|FORK_DEATHSIG
|FORK_LOG
, &pid
);
78 execv(MOUNT_PATH
, STRV_MAKE(MOUNT_PATH
, me
->mnt_dir
, "-o", "remount"));
80 log_error_errno(errno
, "Failed to execute " MOUNT_PATH
": %m");
86 s
= strdup(me
->mnt_dir
);
92 k
= hashmap_put(pids
, PID_TO_PTR(pid
), s
);
101 while (!hashmap_isempty(pids
)) {
105 if (waitid(P_ALL
, 0, &si
, WEXITED
) < 0) {
110 r
= log_error_errno(errno
, "waitid() failed: %m");
114 s
= hashmap_remove(pids
, PID_TO_PTR(si
.si_pid
));
116 if (!is_clean_exit(si
.si_code
, si
.si_status
, EXIT_CLEAN_COMMAND
, NULL
)) {
117 if (si
.si_code
== CLD_EXITED
)
118 log_error(MOUNT_PATH
" for %s exited with exit status %i.", s
, si
.si_status
);
120 log_error(MOUNT_PATH
" for %s terminated by signal %s.", s
, signal_to_string(si
.si_status
));
130 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;