diff options
-rw-r--r-- | src/login/loginctl.c | 32 |
1 files 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; - } - - 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(); + if (r < 0) + return log_error_errno(r, "Failed to create bus connection: %m"); - strv_free(arg_property); + (void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password); - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + return loginctl_main(argc, argv, bus); } + +DEFINE_MAIN_FUNCTION(run); |