summaryrefslogtreecommitdiff
path: root/src/remount-fs
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-11-16 15:13:14 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-11-17 09:13:35 +0100
commit6e61c701f2b3213cfbd8f3f7c2c9e35ccbef2ad4 (patch)
tree5aeaae000cc9666875bbbbba84390dc9a7639e98 /src/remount-fs
parent72d0d7a628050fe657dd9698fcbce7430b2ff2f9 (diff)
downloadsystemd-6e61c701f2b3213cfbd8f3f7c2c9e35ccbef2ad4.tar.gz
remount-fs: configure logging before use and define main through macro
Diffstat (limited to 'src/remount-fs')
-rw-r--r--src/remount-fs/remount-fs.c75
1 files changed, 31 insertions, 44 deletions
diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c
index 9220a00215..9a0c39e16f 100644
--- a/src/remount-fs/remount-fs.c
+++ b/src/remount-fs/remount-fs.c
@@ -22,44 +22,39 @@
* options that are in /etc/fstab that systemd might not have
* respected */
-int main(int argc, char *argv[]) {
+static int run(int argc, char *argv[]) {
_cleanup_hashmap_free_free_ Hashmap *pids = NULL;
_cleanup_endmntent_ FILE *f = NULL;
struct mntent* me;
int r;
- if (argc > 1) {
- log_error("This program takes no argument.");
- return EXIT_FAILURE;
- }
-
log_set_target(LOG_TARGET_AUTO);
log_parse_environment();
log_open();
+ if (argc > 1) {
+ log_error("This program takes no arguments.");
+ return -EINVAL;
+ }
+
umask(0022);
f = setmntent("/etc/fstab", "re");
if (!f) {
- if (errno == ENOENT) {
- r = 0;
- goto finish;
- }
+ if (errno == ENOENT)
+ return 0;
- r = log_error_errno(errno, "Failed to open /etc/fstab: %m");
- goto finish;
+ return log_error_errno(errno, "Failed to open /etc/fstab: %m");
}
pids = hashmap_new(NULL);
- if (!pids) {
- r = log_oom();
- goto finish;
- }
+ if (!pids)
+ return log_oom();
while ((me = getmntent(f))) {
+ _cleanup_free_ char *s = NULL;
pid_t pid;
int k;
- char *s;
/* Remount the root fs, /usr and all API VFS */
if (!mount_point_is_api(me->mnt_dir) &&
@@ -71,7 +66,7 @@ int main(int argc, char *argv[]) {
r = safe_fork("(remount)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_LOG, &pid);
if (r < 0)
- goto finish;
+ return r;
if (r == 0) {
/* Child */
@@ -84,48 +79,40 @@ int main(int argc, char *argv[]) {
/* Parent */
s = strdup(me->mnt_dir);
- if (!s) {
- r = log_oom();
- goto finish;
- }
+ if (!s)
+ return log_oom();
k = hashmap_put(pids, PID_TO_PTR(pid), s);
- if (k < 0) {
- free(s);
- r = log_oom();
- goto finish;
- }
+ if (k < 0)
+ return log_oom();
+ TAKE_PTR(s);
}
r = 0;
while (!hashmap_isempty(pids)) {
siginfo_t si = {};
- char *s;
+ _cleanup_free_ char *s = NULL;
if (waitid(P_ALL, 0, &si, WEXITED) < 0) {
-
if (errno == EINTR)
continue;
- r = log_error_errno(errno, "waitid() failed: %m");
- goto finish;
+ return log_error_errno(errno, "waitid() failed: %m");
}
s = hashmap_remove(pids, PID_TO_PTR(si.si_pid));
- if (s) {
- if (!is_clean_exit(si.si_code, si.si_status, EXIT_CLEAN_COMMAND, NULL)) {
- if (si.si_code == CLD_EXITED)
- log_error(MOUNT_PATH " for %s exited with exit status %i.", s, si.si_status);
- else
- log_error(MOUNT_PATH " for %s terminated by signal %s.", s, signal_to_string(si.si_status));
-
- r = -ENOEXEC;
- }
-
- free(s);
+ if (s &&
+ !is_clean_exit(si.si_code, si.si_status, EXIT_CLEAN_COMMAND, NULL)) {
+ if (si.si_code == CLD_EXITED)
+ log_error(MOUNT_PATH " for %s exited with exit status %i.", s, si.si_status);
+ else
+ log_error(MOUNT_PATH " for %s terminated by signal %s.", s, signal_to_string(si.si_status));
+
+ r = -ENOEXEC;
}
}
-finish:
- return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+ return r;
}
+
+DEFINE_MAIN_FUNCTION(run);