machinectl: use static destructor and DEFINE_MAIN_FUNCTION() macro
This commit is contained in:
parent
a6db316372
commit
f66da783fa
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue