loginctl: use static destructor and DEFINE_MAIN_FUNCTION() macro

This commit is contained in:
Yu Watanabe 2018-11-20 18:15:33 +09:00 committed by Zbigniew Jędrzejewski-Szmek
parent 847da1ac1b
commit eae5c847f8
1 changed files with 12 additions and 20 deletions

View File

@ -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);