1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include <sys/prctl.h>
29 #include "exit-status.h"
31 #include "mount-setup.h"
32 #include "mount-util.h"
33 #include "path-util.h"
34 #include "process-util.h"
35 #include "signal-util.h"
39 /* Goes through /etc/fstab and remounts all API file systems, applying
40 * options that are in /etc/fstab that systemd might not have
43 int main(int argc
, char *argv
[]) {
44 _cleanup_hashmap_free_free_ Hashmap
*pids
= NULL
;
45 _cleanup_endmntent_
FILE *f
= NULL
;
50 log_error("This program takes no argument.");
54 log_set_target(LOG_TARGET_AUTO
);
55 log_parse_environment();
60 f
= setmntent("/etc/fstab", "re");
62 if (errno
== ENOENT
) {
67 r
= log_error_errno(errno
, "Failed to open /etc/fstab: %m");
71 pids
= hashmap_new(NULL
);
77 while ((me
= getmntent(f
))) {
82 /* Remount the root fs, /usr and all API VFS */
83 if (!mount_point_is_api(me
->mnt_dir
) &&
84 !path_equal(me
->mnt_dir
, "/") &&
85 !path_equal(me
->mnt_dir
, "/usr"))
88 log_debug("Remounting %s", me
->mnt_dir
);
92 r
= log_error_errno(errno
, "Failed to fork: %m");
99 (void) reset_all_signal_handlers();
100 (void) reset_signal_mask();
101 (void) prctl(PR_SET_PDEATHSIG
, SIGTERM
);
103 execv(MOUNT_PATH
, STRV_MAKE(MOUNT_PATH
, me
->mnt_dir
, "-o", "remount"));
105 log_error_errno(errno
, "Failed to execute " MOUNT_PATH
": %m");
111 s
= strdup(me
->mnt_dir
);
117 k
= hashmap_put(pids
, PID_TO_PTR(pid
), s
);
126 while (!hashmap_isempty(pids
)) {
130 if (waitid(P_ALL
, 0, &si
, WEXITED
) < 0) {
135 r
= log_error_errno(errno
, "waitid() failed: %m");
139 s
= hashmap_remove(pids
, PID_TO_PTR(si
.si_pid
));
141 if (!is_clean_exit(si
.si_code
, si
.si_status
, EXIT_CLEAN_COMMAND
, NULL
)) {
142 if (si
.si_code
== CLD_EXITED
)
143 log_error(MOUNT_PATH
" for %s exited with exit status %i.", s
, si
.si_status
);
145 log_error(MOUNT_PATH
" for %s terminated by signal %s.", s
, signal_to_string(si
.si_status
));
155 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;