summaryrefslogtreecommitdiff
path: root/src/remount-fs
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-11-19 15:28:17 +0100
committerGitHub <noreply@github.com>2018-11-19 15:28:17 +0100
commit2a44bf5099d4b13d90d4a6c93b404894960487ee (patch)
tree984ba8892e42155bfa981099270e5c7e2f49f51b /src/remount-fs
parent2675747f3cdd6f1e6236bbb2f79abfa53fb307f1 (diff)
parent51e237864221f3edb0c0fb28684901f538341cb1 (diff)
downloadsystemd-2a44bf5099d4b13d90d4a6c93b404894960487ee.tar.gz
Merge pull request #10811 from keszybz/define-main-through-macro
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);