localectl: define main through macro

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-11-20 09:56:18 +01:00
parent 7add4883cb
commit 39daad0a81

View file

@ -15,6 +15,7 @@
#include "fd-util.h"
#include "fileio.h"
#include "locale-util.h"
#include "main-func.h"
#include "pager.h"
#include "proc-cmdline.h"
#include "set.h"
@ -505,8 +506,8 @@ static int localectl_main(sd_bus *bus, int argc, char *argv[]) {
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, "");
@ -515,21 +516,13 @@ 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");
r = localectl_main(bus, argc, argv);
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();
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
return localectl_main(bus, argc, argv);
}
DEFINE_MAIN_FUNCTION(run);