From eae5c847f83b8b852295eaa3cab639ab31002b11 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 20 Nov 2018 18:15:33 +0900 Subject: [PATCH] loginctl: use static destructor and DEFINE_MAIN_FUNCTION() macro --- src/login/loginctl.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/login/loginctl.c b/src/login/loginctl.c index d6250253d6..1f05753dff 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -18,6 +18,7 @@ #include "log.h" #include "logs-show.h" #include "macro.h" +#include "main-func.h" #include "pager.h" #include "parse-util.h" #include "process-util.h" @@ -48,6 +49,8 @@ static bool arg_ask_password = true; static unsigned arg_lines = 10; static OutputMode arg_output = OUTPUT_SHORT; +STATIC_DESTRUCTOR_REGISTER(arg_property, strv_freep); + static OutputFlags get_output_flags(void) { return @@ -1516,8 +1519,8 @@ static int loginctl_main(int argc, char *argv[], sd_bus *bus) { return dispatch_verb(argc, argv, verbs, bus); } -int main(int argc, char *argv[]) { - sd_bus *bus = NULL; +static int run(int argc, char *argv[]) { + _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; int r; setlocale(LC_ALL, ""); @@ -1531,26 +1534,15 @@ int main(int argc, char *argv[]) { r = parse_argv(argc, argv); if (r <= 0) - goto finish; + return r; r = bus_connect_transport(arg_transport, arg_host, false, &bus); - if (r < 0) { - log_error_errno(r, "Failed to create bus connection: %m"); - goto finish; - } + if (r < 0) + return log_error_errno(r, "Failed to create bus connection: %m"); - sd_bus_set_allow_interactive_authorization(bus, arg_ask_password); + (void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password); - r = loginctl_main(argc, argv, bus); - -finish: - /* make sure we terminate the bus connection first, and then close the - * pager, see issue #3543 for the details. */ - sd_bus_flush_close_unref(bus); - pager_close(); - polkit_agent_close(); - - strv_free(arg_property); - - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + return loginctl_main(argc, argv, bus); } + +DEFINE_MAIN_FUNCTION(run);