From: Yu Watanabe Date: Mon, 26 Nov 2018 07:56:58 +0000 (+0900) Subject: wait-online: define main through macro X-Git-Tag: v240~107^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c03a80c41945687ca5deac159a164859ec45511e;p=thirdparty%2Fsystemd.git wait-online: define main through macro --- diff --git a/src/network/wait-online/wait-online.c b/src/network/wait-online/wait-online.c index 7f30862bbfc..71b6cf6b877 100644 --- a/src/network/wait-online/wait-online.c +++ b/src/network/wait-online/wait-online.c @@ -4,6 +4,8 @@ #include "sd-daemon.h" +#include "daemon-util.h" +#include "main-func.h" #include "manager.h" #include "pretty-print.h" #include "signal-util.h" @@ -14,6 +16,9 @@ static usec_t arg_timeout = 120 * USEC_PER_SEC; static char **arg_interfaces = NULL; static char **arg_ignore = NULL; +STATIC_DESTRUCTOR_REGISTER(arg_interfaces, strv_freep); +STATIC_DESTRUCTOR_REGISTER(arg_ignore, strv_freep); + static int help(void) { _cleanup_free_ char *link = NULL; int r; @@ -105,7 +110,8 @@ static int parse_argv(int argc, char *argv[]) { return 1; } -int main(int argc, char *argv[]) { +static int run(int argc, char *argv[]) { + _cleanup_(notify_on_cleanup) const char *notify_message = NULL; _cleanup_(manager_freep) Manager *m = NULL; int r; @@ -123,37 +129,24 @@ int main(int argc, char *argv[]) { assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0); r = manager_new(&m, arg_interfaces, arg_ignore, arg_timeout); - if (r < 0) { - log_error_errno(r, "Could not create manager: %m"); - goto finish; - } + if (r < 0) + return log_error_errno(r, "Could not create manager: %m"); - if (manager_all_configured(m)) { - r = 0; - goto finish; - } + if (manager_all_configured(m)) + goto success; - sd_notify(false, - "READY=1\n" - "STATUS=Waiting for network connections..."); + notify_message = notify_start("READY=1\n" + "STATUS=Waiting for network connections...", + "STATUS=Failed to wait for network connectivity..."); r = sd_event_loop(m->event); - if (r < 0) { - log_error_errno(r, "Event loop failed: %m"); - goto finish; - } - -finish: - strv_free(arg_interfaces); - strv_free(arg_ignore); - - if (r >= 0) { - sd_notify(false, "STATUS=All interfaces configured..."); + if (r < 0) + return log_error_errno(r, "Event loop failed: %m"); - return EXIT_SUCCESS; - } else { - sd_notify(false, "STATUS=Failed waiting for network connectivity..."); +success: + notify_message = "STATUS=All interfaces configured..."; - return EXIT_FAILURE; - } + return 0; } + +DEFINE_MAIN_FUNCTION(run);