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 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
36 "This program takes no arguments.");
40 f
= setmntent("/etc/fstab", "re");
45 return log_error_errno(errno
, "Failed to open /etc/fstab: %m");
48 pids
= hashmap_new(NULL
);
52 while ((me
= getmntent(f
))) {
53 _cleanup_free_
char *s
= NULL
;
57 /* Remount the root fs, /usr and all API VFS */
58 if (!mount_point_is_api(me
->mnt_dir
) &&
59 !path_equal(me
->mnt_dir
, "/") &&
60 !path_equal(me
->mnt_dir
, "/usr"))
63 log_debug("Remounting %s", me
->mnt_dir
);
65 r
= safe_fork("(remount)", FORK_RESET_SIGNALS
|FORK_DEATHSIG
|FORK_RLIMIT_NOFILE_SAFE
|FORK_LOG
, &pid
);
71 execv(MOUNT_PATH
, STRV_MAKE(MOUNT_PATH
, me
->mnt_dir
, "-o", "remount"));
73 log_error_errno(errno
, "Failed to execute " MOUNT_PATH
": %m");
79 s
= strdup(me
->mnt_dir
);
83 k
= hashmap_put(pids
, PID_TO_PTR(pid
), s
);
90 while (!hashmap_isempty(pids
)) {
92 _cleanup_free_
char *s
= NULL
;
94 if (waitid(P_ALL
, 0, &si
, WEXITED
) < 0) {
98 return log_error_errno(errno
, "waitid() failed: %m");
101 s
= hashmap_remove(pids
, PID_TO_PTR(si
.si_pid
));
103 !is_clean_exit(si
.si_code
, si
.si_status
, EXIT_CLEAN_COMMAND
, NULL
)) {
104 if (si
.si_code
== CLD_EXITED
)
105 log_error(MOUNT_PATH
" for %s exited with exit status %i.", s
, si
.si_status
);
107 log_error(MOUNT_PATH
" for %s terminated by signal %s.", s
, signal_to_string(si
.si_status
));
116 DEFINE_MAIN_FUNCTION(run
);