diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-12-15 17:09:18 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-12-15 20:52:28 +0100 |
commit | efeb853fbd03aaa63d657623139b30581d386096 (patch) | |
tree | 299ef166767571ad1974955d661dd997d424f52d /src | |
parent | 72c7329b6eda90bbbf83354c10c51f60c3523870 (diff) | |
download | systemd-efeb853fbd03aaa63d657623139b30581d386096.tar.gz systemd-efeb853fbd03aaa63d657623139b30581d386096.tar.bz2 systemd-efeb853fbd03aaa63d657623139b30581d386096.zip |
main: split out code that collects passed fds
More refactoring to make main() more digestable
Diffstat (limited to 'src')
-rw-r--r-- | src/core/main.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/src/core/main.c b/src/core/main.c index 7e3658f711..8dd4da1203 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -2215,6 +2215,26 @@ static void log_taint_string(Manager *m) { NULL); } +static int collect_fds(FDSet **ret_fds, const char **ret_error_message) { + int r; + + assert(ret_fds); + assert(ret_error_message); + + r = fdset_new_fill(ret_fds); + if (r < 0) { + *ret_error_message = "Failed to allocate fd set"; + return log_emergency_errno(r, "Failed to allocate fd set: %m"); + } + + fdset_cloexec(*ret_fds, true); + + if (arg_serialization) + assert_se(fdset_remove(*ret_fds, fileno(arg_serialization)) >= 0); + + return 0; +} + int main(int argc, char *argv[]) { Manager *m = NULL; int r, retval = EXIT_FAILURE; @@ -2411,20 +2431,13 @@ int main(int argc, char *argv[]) { if (arg_action == ACTION_RUN) { - /* Close logging fds, in order not to confuse fdset below */ + /* Close logging fds, in order not to confuse collecting passed fds and terminal logic below */ log_close(); /* Remember open file descriptors for later deserialization */ - r = fdset_new_fill(&fds); - if (r < 0) { - log_emergency_errno(r, "Failed to allocate fd set: %m"); - error_message = "Failed to allocate fd set"; + r = collect_fds(&fds, &error_message); + if (r < 0) goto finish; - } else - fdset_cloexec(fds, true); - - if (arg_serialization) - assert_se(fdset_remove(fds, fileno(arg_serialization)) >= 0); if (arg_system) { /* Become a session leader if we aren't one yet. */ |