1 /* SPDX-License-Identifier: LGPL-2.1+ */
11 #include "exit-status.h"
13 #include "main-func.h"
14 #include "mount-setup.h"
15 #include "mount-util.h"
16 #include "path-util.h"
17 #include "process-util.h"
18 #include "signal-util.h"
22 /* Goes through /etc/fstab and remounts all API file systems, applying
23 * options that are in /etc/fstab that systemd might not have
26 static int run(int argc
, char *argv
[]) {
27 _cleanup_hashmap_free_free_ Hashmap
*pids
= NULL
;
28 _cleanup_endmntent_
FILE *f
= NULL
;
35 log_error("This program takes no arguments.");
41 f
= setmntent("/etc/fstab", "re");
46 return log_error_errno(errno
, "Failed to open /etc/fstab: %m");
49 pids
= hashmap_new(NULL
);
53 while ((me
= getmntent(f
))) {
54 _cleanup_free_
char *s
= NULL
;
58 /* Remount the root fs, /usr and all API VFS */
59 if (!mount_point_is_api(me
->mnt_dir
) &&
60 !path_equal(me
->mnt_dir
, "/") &&
61 !path_equal(me
->mnt_dir
, "/usr"))
64 log_debug("Remounting %s", me
->mnt_dir
);
66 r
= safe_fork("(remount)", FORK_RESET_SIGNALS
|FORK_DEATHSIG
|FORK_LOG
, &pid
);
72 execv(MOUNT_PATH
, STRV_MAKE(MOUNT_PATH
, me
->mnt_dir
, "-o", "remount"));
74 log_error_errno(errno
, "Failed to execute " MOUNT_PATH
": %m");
80 s
= strdup(me
->mnt_dir
);
84 k
= hashmap_put(pids
, PID_TO_PTR(pid
), s
);
91 while (!hashmap_isempty(pids
)) {
93 _cleanup_free_
char *s
= NULL
;
95 if (waitid(P_ALL
, 0, &si
, WEXITED
) < 0) {
99 return log_error_errno(errno
, "waitid() failed: %m");
102 s
= hashmap_remove(pids
, PID_TO_PTR(si
.si_pid
));
104 !is_clean_exit(si
.si_code
, si
.si_status
, EXIT_CLEAN_COMMAND
, NULL
)) {
105 if (si
.si_code
== CLD_EXITED
)
106 log_error(MOUNT_PATH
" for %s exited with exit status %i.", s
, si
.si_status
);
108 log_error(MOUNT_PATH
" for %s terminated by signal %s.", s
, signal_to_string(si
.si_status
));
117 DEFINE_MAIN_FUNCTION(run
);