diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-20 18:21:01 +0900 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-20 18:40:02 +0100 |
commit | f66da783fa544e4a4cc5cd48fe49f0cf5adadcfb (patch) | |
tree | 4f51ac7375beed45744d4e6e33ad86162e233a03 | |
parent | a6db316372a9d4c4c8c6d7cd1841b3b5630b4428 (diff) | |
download | systemd-f66da783fa544e4a4cc5cd48fe49f0cf5adadcfb.tar.gz |
machinectl: use static destructor and DEFINE_MAIN_FUNCTION() macro
-rw-r--r-- | src/machine/machinectl.c | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 241e175ee6..db768ffff4 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -32,6 +32,7 @@ #include "log.h" #include "logs-show.h" #include "macro.h" +#include "main-func.h" #include "mkdir.h" #include "pager.h" #include "parse-util.h" @@ -63,7 +64,7 @@ static bool arg_legend = true; static const char *arg_kill_who = NULL; static int arg_signal = SIGTERM; static BusTransport arg_transport = BUS_TRANSPORT_LOCAL; -static char *arg_host = NULL; +static const char *arg_host = NULL; static bool arg_read_only = false; static bool arg_mkdir = false; static bool arg_quiet = false; @@ -77,6 +78,9 @@ static const char *arg_uid = NULL; static char **arg_setenv = NULL; static int arg_addrs = 1; +STATIC_DESTRUCTOR_REGISTER(arg_property, strv_freep); +STATIC_DESTRUCTOR_REGISTER(arg_setenv, strv_freep); + static OutputFlags get_output_flags(void) { return arg_all * OUTPUT_SHOW_ALL | @@ -3026,8 +3030,8 @@ static int machinectl_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, ""); @@ -3041,27 +3045,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"); (void) sd_bus_set_allow_interactive_authorization(bus, arg_ask_password); - r = machinectl_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); - strv_free(arg_setenv); - - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + return machinectl_main(argc, argv, bus); } + +DEFINE_MAIN_FUNCTION(run); |