summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-11-20 18:15:33 +0900
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-11-20 18:40:02 +0100
commiteae5c847f83b8b852295eaa3cab639ab31002b11 (patch)
treeefb419ea9803f1dcd9389f7975b391582de73872 /src/login
parent847da1ac1be8665f049e68978bd7d1ebd1c66fdc (diff)
downloadsystemd-eae5c847f83b8b852295eaa3cab639ab31002b11.tar.gz
systemd-eae5c847f83b8b852295eaa3cab639ab31002b11.tar.bz2
systemd-eae5c847f83b8b852295eaa3cab639ab31002b11.zip
loginctl: use static destructor and DEFINE_MAIN_FUNCTION() macro
Diffstat (limited to 'src/login')
-rw-r--r--src/login/loginctl.c32
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);