diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-20 18:03:50 +0900 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-20 18:40:02 +0100 |
commit | 85ae63ee874af8d22e4bbed3dd459ded8cfbcd49 (patch) | |
tree | 47a624cb923bc502e9aa4a1dc0347fb80767ce38 | |
parent | 77182cc65ee853d9278543cff2f517af4c27bac3 (diff) | |
download | systemd-85ae63ee874af8d22e4bbed3dd459ded8cfbcd49.tar.gz systemd-85ae63ee874af8d22e4bbed3dd459ded8cfbcd49.tar.bz2 systemd-85ae63ee874af8d22e4bbed3dd459ded8cfbcd49.zip |
hostnamed: use DEFINE_MAIN_FUNCTION() macro
This also renames context_free() to context_clear().
-rw-r--r-- | src/hostname/hostnamed.c | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 219602c55a..d14073ace0 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -13,6 +13,7 @@ #include "fileio-label.h" #include "hostname-util.h" #include "id128-util.h" +#include "main-func.h" #include "os-util.h" #include "parse-util.h" #include "path-util.h" @@ -58,7 +59,7 @@ static void context_reset(Context *c) { c->data[p] = mfree(c->data[p]); } -static void context_free(Context *c) { +static void context_clear(Context *c) { assert(c); context_reset(c); @@ -701,8 +702,8 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) { return 0; } -int main(int argc, char *argv[]) { - Context context = {}; +static int run(int argc, char *argv[]) { + _cleanup_(context_clear) Context context = {}; _cleanup_(sd_event_unrefp) sd_event *event = NULL; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; int r; @@ -714,50 +715,38 @@ int main(int argc, char *argv[]) { if (argc != 1) { log_error("This program takes no arguments."); - r = -EINVAL; - goto finish; + return -EINVAL; } assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0); r = sd_event_default(&event); - if (r < 0) { - log_error_errno(r, "Failed to allocate event loop: %m"); - goto finish; - } + if (r < 0) + return log_error_errno(r, "Failed to allocate event loop: %m"); (void) sd_event_set_watchdog(event, true); r = sd_event_add_signal(event, NULL, SIGINT, NULL, NULL); - if (r < 0) { - log_error_errno(r, "Failed to install SIGINT handler: %m"); - goto finish; - } + if (r < 0) + return log_error_errno(r, "Failed to install SIGINT handler: %m"); r = sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL); - if (r < 0) { - log_error_errno(r, "Failed to install SIGTERM handler: %m"); - goto finish; - } + if (r < 0) + return log_error_errno(r, "Failed to install SIGTERM handler: %m"); r = connect_bus(&context, event, &bus); if (r < 0) - goto finish; + return r; r = context_read_data(&context); - if (r < 0) { - log_error_errno(r, "Failed to read hostname and machine information: %m"); - goto finish; - } + if (r < 0) + return log_error_errno(r, "Failed to read hostname and machine information: %m"); r = bus_event_loop_with_idle(event, bus, "org.freedesktop.hostname1", DEFAULT_EXIT_USEC, NULL, NULL); - if (r < 0) { - log_error_errno(r, "Failed to run event loop: %m"); - goto finish; - } - -finish: - context_free(&context); + if (r < 0) + return log_error_errno(r, "Failed to run event loop: %m"); - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + return 0; } + +DEFINE_MAIN_FUNCTION(run); |