2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
28 #include "alloc-util.h"
29 #include "bus-error.h"
31 //#include "cgroup-show.h"
32 #include "cgroup-util.h"
34 //#include "logs-show.h"
37 #include "parse-util.h"
38 #include "process-util.h"
39 #include "signal-util.h"
40 #include "spawn-polkit-agent.h"
42 #include "sysfs-show.h"
43 #include "terminal-util.h"
44 #include "unit-name.h"
45 #include "user-util.h"
49 /// Additional includes for elogind
50 #include "logind-action.h"
51 #include "musl_missing.h"
53 #include "stdio-util.h"
56 static char **arg_property = NULL;
57 static bool arg_all = false;
58 static bool arg_value = false;
59 static bool arg_full = false;
60 static bool arg_no_pager = false;
61 static bool arg_no_wall = false;
62 static bool arg_legend = true;
63 static const char *arg_kill_who = NULL;
64 static int arg_signal = SIGTERM;
65 static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
66 static char *arg_host = NULL;
67 static usec_t arg_when = 0;
68 static char **arg_wall = NULL;
69 static bool arg_ask_password = true;
70 static bool arg_ignore_inhibitors = false;
71 #if 0 /// UNNEEDED by elogind
72 static unsigned arg_lines = 10;
73 static OutputMode arg_output = OUTPUT_SHORT;
84 ACTION_CANCEL_SHUTDOWN,
89 static void polkit_agent_open_if_enabled(void) {
91 /* Open the polkit agent as a child process if necessary */
93 if (!arg_ask_password)
96 if (arg_transport != BUS_TRANSPORT_LOCAL)
102 #if 0 /// UNNEEDED by elogind
103 static OutputFlags get_output_flags(void) {
106 arg_all * OUTPUT_SHOW_ALL |
107 arg_full * OUTPUT_FULL_WIDTH |
108 (!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
109 colors_enabled() * OUTPUT_COLOR;
113 static int list_sessions(int argc, char *argv[], void *userdata) {
114 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
115 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
116 const char *id, *user, *seat, *object;
117 sd_bus *bus = userdata;
125 pager_open(arg_no_pager, false);
127 r = sd_bus_call_method(
129 "org.freedesktop.login1",
130 "/org/freedesktop/login1",
131 "org.freedesktop.login1.Manager",
136 log_error("Failed to list sessions: %s", bus_error_message(&error, r));
140 r = sd_bus_message_enter_container(reply, 'a', "(susso)");
142 return bus_log_parse_error(r);
145 printf("%10s %10s %-16s %-16s\n", "SESSION", "UID", "USER", "SEAT");
147 while ((r = sd_bus_message_read(reply, "(susso)", &id, &uid, &user, &seat, &object)) > 0) {
148 printf("%10s %10u %-16s %-16s\n", id, (unsigned) uid, user, seat);
152 return bus_log_parse_error(r);
155 printf("\n%u sessions listed.\n", k);
160 static int list_users(int argc, char *argv[], void *userdata) {
161 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
162 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
163 const char *user, *object;
164 sd_bus *bus = userdata;
172 pager_open(arg_no_pager, false);
174 r = sd_bus_call_method(
176 "org.freedesktop.login1",
177 "/org/freedesktop/login1",
178 "org.freedesktop.login1.Manager",
183 log_error("Failed to list users: %s", bus_error_message(&error, r));
187 r = sd_bus_message_enter_container(reply, 'a', "(uso)");
189 return bus_log_parse_error(r);
192 printf("%10s %-16s\n", "UID", "USER");
194 while ((r = sd_bus_message_read(reply, "(uso)", &uid, &user, &object)) > 0) {
195 printf("%10u %-16s\n", (unsigned) uid, user);
199 return bus_log_parse_error(r);
202 printf("\n%u users listed.\n", k);
207 static int list_seats(int argc, char *argv[], void *userdata) {
208 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
209 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
210 const char *seat, *object;
211 sd_bus *bus = userdata;
218 pager_open(arg_no_pager, false);
220 r = sd_bus_call_method(
222 "org.freedesktop.login1",
223 "/org/freedesktop/login1",
224 "org.freedesktop.login1.Manager",
229 log_error("Failed to list seats: %s", bus_error_message(&error, r));
233 r = sd_bus_message_enter_container(reply, 'a', "(so)");
235 return bus_log_parse_error(r);
238 printf("%-16s\n", "SEAT");
240 while ((r = sd_bus_message_read(reply, "(so)", &seat, &object)) > 0) {
241 printf("%-16s\n", seat);
245 return bus_log_parse_error(r);
248 printf("\n%u seats listed.\n", k);
253 #if 0 /// UNNEEDED by elogind
254 static int show_unit_cgroup(sd_bus *bus, const char *interface, const char *unit, pid_t leader) {
255 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
256 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
257 _cleanup_free_ char *path = NULL;
265 path = unit_dbus_path_from_name(unit);
269 r = sd_bus_get_property(
271 "org.freedesktop.systemd1",
279 return log_error_errno(r, "Failed to query ControlGroup: %s", bus_error_message(&error, r));
281 r = sd_bus_message_read(reply, "s", &cgroup);
283 return bus_log_parse_error(r);
294 r = unit_show_processes(bus, unit, cgroup, "\t\t ", c, get_output_flags(), &error);
297 if (arg_transport == BUS_TRANSPORT_REMOTE)
300 /* Fallback for older systemd versions where the GetUnitProcesses() call is not yet available */
302 if (cg_is_empty_recursive(SYSTEMD_CGROUP_CONTROLLER, cgroup) != 0 && leader <= 0)
305 show_cgroup_and_extra(SYSTEMD_CGROUP_CONTROLLER, cgroup, "\t\t ", c, &leader, leader > 0, get_output_flags());
307 return log_error_errno(r, "Failed to dump process list: %s", bus_error_message(&error, r));
313 typedef struct SessionStatusInfo {
317 struct dual_timestamp timestamp;
334 typedef struct UserStatusInfo {
338 struct dual_timestamp timestamp;
345 typedef struct SeatStatusInfo {
347 char *active_session;
351 static void session_status_info_clear(SessionStatusInfo *info) {
358 free(info->remote_host);
359 free(info->remote_user);
370 static void user_status_info_clear(UserStatusInfo *info) {
374 strv_free(info->sessions);
381 static void seat_status_info_clear(SeatStatusInfo *info) {
384 free(info->active_session);
385 strv_free(info->sessions);
390 static int prop_map_first_of_struct(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
391 const char *contents;
394 r = sd_bus_message_peek_type(m, NULL, &contents);
398 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_STRUCT, contents);
402 if (contents[0] == 's' || contents[0] == 'o') {
404 char **p = (char **) userdata;
406 r = sd_bus_message_read_basic(m, contents[0], &s);
410 r = free_and_strdup(p, s);
414 r = sd_bus_message_read_basic(m, contents[0], userdata);
419 r = sd_bus_message_skip(m, contents+1);
423 r = sd_bus_message_exit_container(m);
430 static int prop_map_sessions_strv(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) {
437 r = sd_bus_message_enter_container(m, 'a', "(so)");
441 while ((r = sd_bus_message_read(m, "(so)", &name, NULL)) > 0) {
442 r = strv_extend(userdata, name);
449 return sd_bus_message_exit_container(m);
452 static int print_session_status_info(sd_bus *bus, const char *path, bool *new_line) {
454 static const struct bus_properties_map map[] = {
455 { "Id", "s", NULL, offsetof(SessionStatusInfo, id) },
456 { "Name", "s", NULL, offsetof(SessionStatusInfo, name) },
457 { "TTY", "s", NULL, offsetof(SessionStatusInfo, tty) },
458 { "Display", "s", NULL, offsetof(SessionStatusInfo, display) },
459 { "RemoteHost", "s", NULL, offsetof(SessionStatusInfo, remote_host) },
460 { "RemoteUser", "s", NULL, offsetof(SessionStatusInfo, remote_user) },
461 { "Service", "s", NULL, offsetof(SessionStatusInfo, service) },
462 { "Desktop", "s", NULL, offsetof(SessionStatusInfo, desktop) },
463 { "Type", "s", NULL, offsetof(SessionStatusInfo, type) },
464 { "Class", "s", NULL, offsetof(SessionStatusInfo, class) },
465 { "Scope", "s", NULL, offsetof(SessionStatusInfo, scope) },
466 { "State", "s", NULL, offsetof(SessionStatusInfo, state) },
467 { "VTNr", "u", NULL, offsetof(SessionStatusInfo, vtnr) },
468 { "Leader", "u", NULL, offsetof(SessionStatusInfo, leader) },
469 { "Remote", "b", NULL, offsetof(SessionStatusInfo, remote) },
470 { "Timestamp", "t", NULL, offsetof(SessionStatusInfo, timestamp.realtime) },
471 { "TimestampMonotonic", "t", NULL, offsetof(SessionStatusInfo, timestamp.monotonic) },
472 { "User", "(uo)", prop_map_first_of_struct, offsetof(SessionStatusInfo, uid) },
473 { "Seat", "(so)", prop_map_first_of_struct, offsetof(SessionStatusInfo, seat) },
477 char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1;
478 char since2[FORMAT_TIMESTAMP_MAX], *s2;
479 _cleanup_(session_status_info_clear) SessionStatusInfo i = {};
482 r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &i);
484 return log_error_errno(r, "Could not get properties: %m");
491 printf("%s - ", strna(i.id));
494 printf("%s (%u)\n", i.name, (unsigned) i.uid);
496 printf("%u\n", (unsigned) i.uid);
498 s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
499 s2 = format_timestamp(since2, sizeof(since2), i.timestamp.realtime);
502 printf("\t Since: %s; %s\n", s2, s1);
504 printf("\t Since: %s\n", s2);
507 _cleanup_free_ char *t = NULL;
509 printf("\t Leader: %u", (unsigned) i.leader);
511 get_process_comm(i.leader, &t);
518 if (!isempty(i.seat)) {
519 printf("\t Seat: %s", i.seat);
522 printf("; vc%u", i.vtnr);
528 printf("\t TTY: %s\n", i.tty);
530 printf("\t Display: %s\n", i.display);
532 if (i.remote_host && i.remote_user)
533 printf("\t Remote: %s@%s\n", i.remote_user, i.remote_host);
534 else if (i.remote_host)
535 printf("\t Remote: %s\n", i.remote_host);
536 else if (i.remote_user)
537 printf("\t Remote: user %s\n", i.remote_user);
539 printf("\t Remote: Yes\n");
542 printf("\t Service: %s", i.service);
545 printf("; type %s", i.type);
548 printf("; class %s", i.class);
552 printf("\t Type: %s", i.type);
555 printf("; class %s", i.class);
559 printf("\t Class: %s\n", i.class);
561 if (!isempty(i.desktop))
562 printf("\t Desktop: %s\n", i.desktop);
565 printf("\t State: %s\n", i.state);
568 printf("\t Unit: %s\n", i.scope);
569 #if 0 /// UNNEEDED by elogind
570 show_unit_cgroup(bus, "org.freedesktop.systemd1.Scope", i.scope, i.leader);
572 if (arg_transport == BUS_TRANSPORT_LOCAL) {
574 show_journal_by_unit(
579 i.timestamp.monotonic,
582 get_output_flags() | OUTPUT_BEGIN_NEWLINE,
583 SD_JOURNAL_LOCAL_ONLY,
593 static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line) {
595 static const struct bus_properties_map map[] = {
596 { "Name", "s", NULL, offsetof(UserStatusInfo, name) },
597 { "Linger", "b", NULL, offsetof(UserStatusInfo, linger) },
598 { "Slice", "s", NULL, offsetof(UserStatusInfo, slice) },
599 { "State", "s", NULL, offsetof(UserStatusInfo, state) },
600 { "UID", "u", NULL, offsetof(UserStatusInfo, uid) },
601 { "Timestamp", "t", NULL, offsetof(UserStatusInfo, timestamp.realtime) },
602 { "TimestampMonotonic", "t", NULL, offsetof(UserStatusInfo, timestamp.monotonic) },
603 { "Display", "(so)", prop_map_first_of_struct, offsetof(UserStatusInfo, display) },
604 { "Sessions", "a(so)", prop_map_sessions_strv, offsetof(UserStatusInfo, sessions) },
608 char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1;
609 char since2[FORMAT_TIMESTAMP_MAX], *s2;
610 _cleanup_(user_status_info_clear) UserStatusInfo i = {};
613 r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &i);
615 return log_error_errno(r, "Could not get properties: %m");
623 printf("%s (%u)\n", i.name, (unsigned) i.uid);
625 printf("%u\n", (unsigned) i.uid);
627 s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
628 s2 = format_timestamp(since2, sizeof(since2), i.timestamp.realtime);
631 printf("\t Since: %s; %s\n", s2, s1);
633 printf("\t Since: %s\n", s2);
635 if (!isempty(i.state))
636 printf("\t State: %s\n", i.state);
638 if (!strv_isempty(i.sessions)) {
640 printf("\tSessions:");
642 STRV_FOREACH(l, i.sessions)
644 streq_ptr(*l, i.display) ? "*" : "",
650 printf("\t Linger: %s\n", yes_no(i.linger));
653 printf("\t Unit: %s\n", i.slice);
654 #if 0 /// UNNEEDED by elogind
655 show_unit_cgroup(bus, "org.freedesktop.systemd1.Slice", i.slice, 0);
657 show_journal_by_unit(
662 i.timestamp.monotonic,
665 get_output_flags() | OUTPUT_BEGIN_NEWLINE,
666 SD_JOURNAL_LOCAL_ONLY,
675 static int print_seat_status_info(sd_bus *bus, const char *path, bool *new_line) {
677 static const struct bus_properties_map map[] = {
678 { "Id", "s", NULL, offsetof(SeatStatusInfo, id) },
679 { "ActiveSession", "(so)", prop_map_first_of_struct, offsetof(SeatStatusInfo, active_session) },
680 { "Sessions", "a(so)", prop_map_sessions_strv, offsetof(SeatStatusInfo, sessions) },
684 _cleanup_(seat_status_info_clear) SeatStatusInfo i = {};
687 r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &i);
689 return log_error_errno(r, "Could not get properties: %m");
696 printf("%s\n", strna(i.id));
698 if (!strv_isempty(i.sessions)) {
700 printf("\tSessions:");
702 STRV_FOREACH(l, i.sessions) {
703 if (streq_ptr(*l, i.active_session))
712 if (arg_transport == BUS_TRANSPORT_LOCAL) {
721 printf("\t Devices:\n");
723 show_sysfs(i.id, "\t\t ", c);
729 #define property(name, fmt, ...) \
732 printf(fmt "\n", __VA_ARGS__); \
734 printf("%s=" fmt "\n", name, __VA_ARGS__); \
737 static int print_property(const char *name, sd_bus_message *m, const char *contents) {
744 if (arg_property && !strv_find(arg_property, name))
745 /* skip what we didn't read */
746 return sd_bus_message_skip(m, contents);
748 switch (contents[0]) {
750 case SD_BUS_TYPE_STRUCT_BEGIN:
752 if (contents[1] == SD_BUS_TYPE_STRING && STR_IN_SET(name, "Display", "Seat", "ActiveSession")) {
755 r = sd_bus_message_read(m, "(so)", &s, NULL);
757 return bus_log_parse_error(r);
759 if (arg_all || !isempty(s))
760 property(name, "%s", s);
764 } else if (contents[1] == SD_BUS_TYPE_UINT32 && streq(name, "User")) {
767 r = sd_bus_message_read(m, "(uo)", &uid, NULL);
769 return bus_log_parse_error(r);
771 if (!uid_is_valid(uid)) {
772 log_error("Invalid user ID: " UID_FMT, uid);
776 property(name, UID_FMT, uid);
782 case SD_BUS_TYPE_ARRAY:
784 if (contents[1] == SD_BUS_TYPE_STRUCT_BEGIN && streq(name, "Sessions")) {
788 r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(so)");
790 return bus_log_parse_error(r);
795 while ((r = sd_bus_message_read(m, "(so)", &s, NULL)) > 0) {
796 printf("%s%s", space ? " " : "", s);
800 if (space || !arg_value)
804 return bus_log_parse_error(r);
806 r = sd_bus_message_exit_container(m);
808 return bus_log_parse_error(r);
816 r = bus_print_property(name, m, arg_value, arg_all);
818 return bus_log_parse_error(r);
821 r = sd_bus_message_skip(m, contents);
823 return bus_log_parse_error(r);
826 printf("%s=[unprintable]\n", name);
832 static int show_properties(sd_bus *bus, const char *path, bool *new_line) {
833 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
834 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
841 r = sd_bus_call_method(
843 "org.freedesktop.login1",
845 "org.freedesktop.DBus.Properties",
851 return log_error_errno(r, "Failed to get properties: %s", bus_error_message(&error, r));
853 r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "{sv}");
855 return bus_log_parse_error(r);
862 while ((r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0) {
863 const char *name, *contents;
865 r = sd_bus_message_read(reply, "s", &name);
867 return bus_log_parse_error(r);
869 r = sd_bus_message_peek_type(reply, NULL, &contents);
871 return bus_log_parse_error(r);
873 r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_VARIANT, contents);
875 return bus_log_parse_error(r);
877 r = print_property(name, reply, contents);
881 r = sd_bus_message_exit_container(reply);
883 return bus_log_parse_error(r);
885 r = sd_bus_message_exit_container(reply);
887 return bus_log_parse_error(r);
890 return bus_log_parse_error(r);
892 r = sd_bus_message_exit_container(reply);
894 return bus_log_parse_error(r);
899 static int show_session(int argc, char *argv[], void *userdata) {
900 bool properties, new_line = false;
901 sd_bus *bus = userdata;
907 properties = !strstr(argv[0], "status");
909 pager_open(arg_no_pager, false);
912 /* If not argument is specified inspect the manager
915 return show_properties(bus, "/org/freedesktop/login1", &new_line);
917 /* And in the pretty case, show data of the calling session */
918 return print_session_status_info(bus, "/org/freedesktop/login1/session/self", &new_line);
921 for (i = 1; i < argc; i++) {
922 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
923 _cleanup_(sd_bus_message_unrefp) sd_bus_message * reply = NULL;
924 const char *path = NULL;
926 r = sd_bus_call_method(
928 "org.freedesktop.login1",
929 "/org/freedesktop/login1",
930 "org.freedesktop.login1.Manager",
935 log_error("Failed to get session: %s", bus_error_message(&error, r));
939 r = sd_bus_message_read(reply, "o", &path);
941 return bus_log_parse_error(r);
944 r = show_properties(bus, path, &new_line);
946 r = print_session_status_info(bus, path, &new_line);
955 static int show_user(int argc, char *argv[], void *userdata) {
956 bool properties, new_line = false;
957 sd_bus *bus = userdata;
963 properties = !strstr(argv[0], "status");
965 pager_open(arg_no_pager, false);
968 /* If not argument is specified inspect the manager
971 return show_properties(bus, "/org/freedesktop/login1", &new_line);
973 return print_user_status_info(bus, "/org/freedesktop/login1/user/self", &new_line);
976 for (i = 1; i < argc; i++) {
977 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
978 _cleanup_(sd_bus_message_unrefp) sd_bus_message * reply = NULL;
979 const char *path = NULL;
982 r = get_user_creds((const char**) (argv+i), &uid, NULL, NULL, NULL);
984 return log_error_errno(r, "Failed to look up user %s: %m", argv[i]);
986 r = sd_bus_call_method(
988 "org.freedesktop.login1",
989 "/org/freedesktop/login1",
990 "org.freedesktop.login1.Manager",
993 "u", (uint32_t) uid);
995 log_error("Failed to get user: %s", bus_error_message(&error, r));
999 r = sd_bus_message_read(reply, "o", &path);
1001 return bus_log_parse_error(r);
1004 r = show_properties(bus, path, &new_line);
1006 r = print_user_status_info(bus, path, &new_line);
1015 static int show_seat(int argc, char *argv[], void *userdata) {
1016 bool properties, new_line = false;
1017 sd_bus *bus = userdata;
1023 properties = !strstr(argv[0], "status");
1025 pager_open(arg_no_pager, false);
1028 /* If not argument is specified inspect the manager
1031 return show_properties(bus, "/org/freedesktop/login1", &new_line);
1033 return print_seat_status_info(bus, "/org/freedesktop/login1/seat/self", &new_line);
1036 for (i = 1; i < argc; i++) {
1037 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1038 _cleanup_(sd_bus_message_unrefp) sd_bus_message * reply = NULL;
1039 const char *path = NULL;
1041 r = sd_bus_call_method(
1043 "org.freedesktop.login1",
1044 "/org/freedesktop/login1",
1045 "org.freedesktop.login1.Manager",
1050 log_error("Failed to get seat: %s", bus_error_message(&error, r));
1054 r = sd_bus_message_read(reply, "o", &path);
1056 return bus_log_parse_error(r);
1059 r = show_properties(bus, path, &new_line);
1061 r = print_seat_status_info(bus, path, &new_line);
1070 static int activate(int argc, char *argv[], void *userdata) {
1071 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1072 sd_bus *bus = userdata;
1073 char *short_argv[3];
1079 polkit_agent_open_if_enabled();
1082 /* No argument? Let's convert this into the empty
1083 * session name, which the calls will then resolve to
1084 * the caller's session. */
1086 short_argv[0] = argv[0];
1087 short_argv[1] = (char*) "";
1088 short_argv[2] = NULL;
1094 for (i = 1; i < argc; i++) {
1096 r = sd_bus_call_method(
1098 "org.freedesktop.login1",
1099 "/org/freedesktop/login1",
1100 "org.freedesktop.login1.Manager",
1101 streq(argv[0], "lock-session") ? "LockSession" :
1102 streq(argv[0], "unlock-session") ? "UnlockSession" :
1103 streq(argv[0], "terminate-session") ? "TerminateSession" :
1108 log_error("Failed to issue method call: %s", bus_error_message(&error, -r));
1116 static int kill_session(int argc, char *argv[], void *userdata) {
1117 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1118 sd_bus *bus = userdata;
1124 polkit_agent_open_if_enabled();
1127 arg_kill_who = "all";
1129 for (i = 1; i < argc; i++) {
1131 r = sd_bus_call_method(
1133 "org.freedesktop.login1",
1134 "/org/freedesktop/login1",
1135 "org.freedesktop.login1.Manager",
1138 "ssi", argv[i], arg_kill_who, arg_signal);
1140 log_error("Could not kill session: %s", bus_error_message(&error, -r));
1148 static int enable_linger(int argc, char *argv[], void *userdata) {
1149 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1150 sd_bus *bus = userdata;
1151 char* short_argv[3];
1158 polkit_agent_open_if_enabled();
1160 b = streq(argv[0], "enable-linger");
1163 short_argv[0] = argv[0];
1164 short_argv[1] = (char*) "";
1165 short_argv[2] = NULL;
1170 for (i = 1; i < argc; i++) {
1173 if (isempty(argv[i]))
1176 r = get_user_creds((const char**) (argv+i), &uid, NULL, NULL, NULL);
1178 return log_error_errno(r, "Failed to look up user %s: %m", argv[i]);
1181 r = sd_bus_call_method(
1183 "org.freedesktop.login1",
1184 "/org/freedesktop/login1",
1185 "org.freedesktop.login1.Manager",
1188 "ubb", (uint32_t) uid, b, true);
1190 log_error("Could not enable linger: %s", bus_error_message(&error, -r));
1198 static int terminate_user(int argc, char *argv[], void *userdata) {
1199 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1200 sd_bus *bus = userdata;
1206 polkit_agent_open_if_enabled();
1208 for (i = 1; i < argc; i++) {
1211 r = get_user_creds((const char**) (argv+i), &uid, NULL, NULL, NULL);
1213 return log_error_errno(r, "Failed to look up user %s: %m", argv[i]);
1215 r = sd_bus_call_method(
1217 "org.freedesktop.login1",
1218 "/org/freedesktop/login1",
1219 "org.freedesktop.login1.Manager",
1222 "u", (uint32_t) uid);
1224 log_error("Could not terminate user: %s", bus_error_message(&error, -r));
1232 static int kill_user(int argc, char *argv[], void *userdata) {
1233 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1234 sd_bus *bus = userdata;
1240 polkit_agent_open_if_enabled();
1243 arg_kill_who = "all";
1245 for (i = 1; i < argc; i++) {
1248 r = get_user_creds((const char**) (argv+i), &uid, NULL, NULL, NULL);
1250 return log_error_errno(r, "Failed to look up user %s: %m", argv[i]);
1252 r = sd_bus_call_method(
1254 "org.freedesktop.login1",
1255 "/org/freedesktop/login1",
1256 "org.freedesktop.login1.Manager",
1259 "ui", (uint32_t) uid, arg_signal);
1261 log_error("Could not kill user: %s", bus_error_message(&error, -r));
1269 static int attach(int argc, char *argv[], void *userdata) {
1270 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1271 sd_bus *bus = userdata;
1277 polkit_agent_open_if_enabled();
1279 for (i = 2; i < argc; i++) {
1281 r = sd_bus_call_method(
1283 "org.freedesktop.login1",
1284 "/org/freedesktop/login1",
1285 "org.freedesktop.login1.Manager",
1288 "ssb", argv[1], argv[i], true);
1291 log_error("Could not attach device: %s", bus_error_message(&error, -r));
1299 static int flush_devices(int argc, char *argv[], void *userdata) {
1300 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1301 sd_bus *bus = userdata;
1307 polkit_agent_open_if_enabled();
1309 r = sd_bus_call_method(
1311 "org.freedesktop.login1",
1312 "/org/freedesktop/login1",
1313 "org.freedesktop.login1.Manager",
1318 log_error("Could not flush devices: %s", bus_error_message(&error, -r));
1323 static int lock_sessions(int argc, char *argv[], void *userdata) {
1324 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1325 sd_bus *bus = userdata;
1331 polkit_agent_open_if_enabled();
1333 r = sd_bus_call_method(
1335 "org.freedesktop.login1",
1336 "/org/freedesktop/login1",
1337 "org.freedesktop.login1.Manager",
1338 streq(argv[0], "lock-sessions") ? "LockSessions" : "UnlockSessions",
1342 log_error("Could not lock sessions: %s", bus_error_message(&error, -r));
1347 static int terminate_seat(int argc, char *argv[], void *userdata) {
1348 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1349 sd_bus *bus = userdata;
1355 polkit_agent_open_if_enabled();
1357 for (i = 1; i < argc; i++) {
1359 r = sd_bus_call_method(
1361 "org.freedesktop.login1",
1362 "/org/freedesktop/login1",
1363 "org.freedesktop.login1.Manager",
1368 log_error("Could not terminate seat: %s", bus_error_message(&error, -r));
1376 static int logind_set_wall_message(sd_bus* bus, const char* msg) {
1377 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1378 _cleanup_free_ char *m = NULL;
1381 if (strv_extend(&arg_wall, msg) < 0)
1384 m = strv_join(arg_wall, " ");
1388 r = sd_bus_call_method(
1390 "org.freedesktop.login1",
1391 "/org/freedesktop/login1",
1392 "org.freedesktop.login1.Manager",
1401 return log_warning_errno(r, "Failed to set wall message, ignoring: %s", bus_error_message(&error, r));
1406 static int elogind_cancel_shutdown(sd_bus *bus, enum action a) {
1407 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1409 static const char *table[_ACTION_MAX] = {
1410 [ACTION_REBOOT] = "The system reboot has been cancelled!",
1411 [ACTION_POWEROFF] = "The system shutdown has been cancelled!"
1414 r = logind_set_wall_message(bus, table[a]);
1417 log_warning_errno(r, "Failed to set wall message, ignoring: %s",
1418 bus_error_message(&error, r));
1419 sd_bus_error_free(&error);
1422 r = sd_bus_call_method(
1424 "org.freedesktop.login1",
1425 "/org/freedesktop/login1",
1426 "org.freedesktop.login1.Manager",
1427 "CancelScheduledShutdown",
1431 return log_warning_errno(r, "Failed to talk to logind, shutdown hasn't been cancelled: %s", bus_error_message(&error, r));
1436 static int elogind_schedule_shutdown(sd_bus *bus, enum action a) {
1437 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1438 const char *method = NULL;
1439 char date[FORMAT_TIMESTAMP_MAX];
1440 char sched_wall[128] = { 0x0 };
1446 polkit_agent_open_if_enabled();
1450 case ACTION_POWEROFF:
1451 method = "poweroff";
1462 xsprintf(sched_wall,
1463 "%s scheduled for %s, use 'loginctl -c' to cancel.",
1464 ACTION_POWEROFF == a ? "Shutdown" : "Reboot",
1465 format_timestamp(date, sizeof(date), arg_when));
1466 r = logind_set_wall_message(bus, sched_wall);
1469 log_warning_errno(r, "Failed to set wall message, ignoring: %s",
1470 bus_error_message(&error, r));
1471 sd_bus_error_free(&error);
1474 r = sd_bus_call_method(
1476 "org.freedesktop.login1",
1477 "/org/freedesktop/login1",
1478 "org.freedesktop.login1.Manager",
1487 log_error("Failed to execute operation: %s", bus_error_message(&error, r));
1492 static int elogind_reboot(sd_bus *bus, enum action a) {
1493 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
1494 const char *method = NULL;
1496 static const char *table[_ACTION_MAX] = {
1497 [ACTION_REBOOT] = "The system is going down for reboot NOW!",
1498 [ACTION_POWEROFF] = "The system is going down for power-off NOW!"
1504 polkit_agent_open_if_enabled();
1508 case ACTION_POWEROFF:
1509 method = "PowerOff";
1516 case ACTION_SUSPEND:
1520 case ACTION_HIBERNATE:
1521 method = "Hibernate";
1524 case ACTION_HYBRID_SLEEP:
1525 method = "HybridSleep";
1532 r = logind_set_wall_message(bus, table[a]);
1535 log_warning_errno(r, "Failed to set wall message, ignoring: %s",
1536 bus_error_message(&error, r));
1537 sd_bus_error_free(&error);
1540 r = sd_bus_call_method(
1542 "org.freedesktop.login1",
1543 "/org/freedesktop/login1",
1544 "org.freedesktop.login1.Manager",
1552 log_error("Failed to execute operation: %s", bus_error_message(&error, r));
1557 static const struct {
1558 HandleAction action;
1560 } action_table[_ACTION_MAX] = {
1561 [ACTION_POWEROFF] = { HANDLE_POWEROFF, "poweroff", },
1562 [ACTION_REBOOT] = { HANDLE_REBOOT, "reboot", },
1563 [ACTION_SUSPEND] = { HANDLE_SUSPEND, "suspend", },
1564 [ACTION_HIBERNATE] = { HANDLE_HIBERNATE, "hibernate", },
1565 [ACTION_HYBRID_SLEEP] = { HANDLE_HYBRID_SLEEP, "hybrid-sleep" },
1568 static enum action verb_to_action(const char *verb) {
1571 for (i = _ACTION_INVALID; i < _ACTION_MAX; i++)
1572 if (streq_ptr(action_table[i].verb, verb))
1575 return _ACTION_INVALID;
1578 static int parse_shutdown_time_spec(const char *t, usec_t *_u) {
1582 if (streq(t, "now"))
1584 else if (!strchr(t, ':')) {
1587 if (safe_atou64(t, &u) < 0)
1590 *_u = now(CLOCK_REALTIME) + USEC_PER_MINUTE * u;
1599 hour = strtol(t, &e, 10);
1600 if (errno > 0 || *e != ':' || hour < 0 || hour > 23)
1603 minute = strtol(e+1, &e, 10);
1604 if (errno > 0 || *e != 0 || minute < 0 || minute > 59)
1607 n = now(CLOCK_REALTIME);
1608 s = (time_t) (n / USEC_PER_SEC);
1610 assert_se(localtime_r(&s, &tm));
1612 tm.tm_hour = (int) hour;
1613 tm.tm_min = (int) minute;
1616 assert_se(s = mktime(&tm));
1618 *_u = (usec_t) s * USEC_PER_SEC;
1621 *_u += USEC_PER_DAY;
1627 static int check_inhibitors(sd_bus* bus, enum action a) {
1628 _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
1629 _cleanup_strv_free_ char **sessions = NULL;
1630 const char *what, *who, *why, *mode;
1636 if (arg_ignore_inhibitors)
1648 r = sd_bus_call_method(
1650 "org.freedesktop.login1",
1651 "/org/freedesktop/login1",
1652 "org.freedesktop.login1.Manager",
1658 /* If logind is not around, then there are no inhibitors... */
1661 r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "(ssssuu)");
1663 return bus_log_parse_error(r);
1665 while ((r = sd_bus_message_read(reply, "(ssssuu)", &what, &who, &why, &mode, &uid, &pid)) > 0) {
1666 _cleanup_free_ char *comm = NULL, *user = NULL;
1667 _cleanup_strv_free_ char **sv = NULL;
1669 if (!streq(mode, "block"))
1672 sv = strv_split(what, ":");
1676 if ((pid_t) pid < 0)
1677 return log_error_errno(ERANGE, "Bad PID %"PRIu32": %m", pid);
1679 if (!strv_contains(sv,
1684 ACTION_KEXEC) ? "shutdown" : "sleep"))
1687 get_process_comm(pid, &comm);
1688 user = uid_to_name(uid);
1690 log_warning("Operation inhibited by \"%s\" (PID "PID_FMT" \"%s\", user %s), reason is \"%s\".",
1691 who, (pid_t) pid, strna(comm), strna(user), why);
1696 return bus_log_parse_error(r);
1698 r = sd_bus_message_exit_container(reply);
1700 return bus_log_parse_error(r);
1702 /* Check for current sessions */
1703 sd_get_sessions(&sessions);
1704 STRV_FOREACH(s, sessions) {
1705 _cleanup_free_ char *type = NULL, *tty = NULL, *seat = NULL, *user = NULL, *service = NULL, *class = NULL;
1707 if (sd_session_get_uid(*s, &uid) < 0 || uid == getuid())
1710 if (sd_session_get_class(*s, &class) < 0 || !streq(class, "user"))
1713 if (sd_session_get_type(*s, &type) < 0 || (!streq(type, "x11") && !streq(type, "tty")))
1716 sd_session_get_tty(*s, &tty);
1717 sd_session_get_seat(*s, &seat);
1718 sd_session_get_service(*s, &service);
1719 user = uid_to_name(uid);
1721 log_warning("User %s is logged in on %s.", strna(user), isempty(tty) ? (isempty(seat) ? strna(service) : seat) : tty);
1728 log_error("Please retry operation after closing inhibitors and logging out other users.\nAlternatively, ignore inhibitors and users with 'systemctl %s -i'.",
1729 action_table[a].verb);
1734 static int start_special(int argc, char *argv[], void *userdata) {
1735 sd_bus *bus = userdata;
1742 a = verb_to_action(argv[0]);
1744 /* Switch to cancel shutdown, if a shutdown action was requested,
1745 and the option to cancel it was set: */
1746 if ( IN_SET(a, ACTION_POWEROFF, ACTION_REBOOT)
1747 && (arg_action == ACTION_CANCEL_SHUTDOWN) )
1748 return elogind_cancel_shutdown(bus, a);
1750 r = check_inhibitors(bus, a);
1754 /* No power off actions in chroot environments */
1755 if ((a == ACTION_POWEROFF ||
1756 a == ACTION_REBOOT) &&
1757 (running_in_chroot() > 0) ) {
1758 log_info("Running in chroot, ignoring request.");
1762 /* Check time arguments */
1763 if ( IN_SET(a, ACTION_POWEROFF, ACTION_REBOOT)
1765 && (arg_action != ACTION_CANCEL_SHUTDOWN) ) {
1766 r = parse_shutdown_time_spec(argv[1], &arg_when);
1768 log_error("Failed to parse time specification: %s", argv[optind]);
1772 arg_when = now(CLOCK_REALTIME) + USEC_PER_MINUTE;
1774 /* The optional user wall message must be set */
1775 if ((argc > 1) && (arg_action == ACTION_CANCEL_SHUTDOWN) )
1776 /* No time argument for shutdown cancel */
1779 /* We skip the time argument */
1783 arg_wall = strv_copy(wall);
1788 /* Perform requested action */
1794 ACTION_HYBRID_SLEEP)) {
1796 return elogind_schedule_shutdown(bus, a);
1798 return elogind_reboot(bus, a);
1804 static int help(int argc, char *argv[], void *userdata) {
1806 printf("%s [OPTIONS...] {COMMAND} ...\n\n"
1807 "Send control commands to or query the login manager.\n\n"
1808 " -h --help Show this help\n"
1809 " --version Show package version\n"
1810 " --no-pager Do not pipe output into a pager\n"
1811 " --no-wall Do not print any wall message\n"
1812 " --no-legend Do not show the headers and footers\n"
1813 " --no-ask-password Don't prompt for password\n"
1814 " -H --host=[USER@]HOST Operate on remote host\n"
1815 " -M --machine=CONTAINER Operate on local container\n"
1816 " -p --property=NAME Show only properties by this name\n"
1817 " -a --all Show all properties, including empty ones\n"
1818 " --value When showing properties, only print the value\n"
1819 " -l --full Do not ellipsize output\n"
1820 " --kill-who=WHO Who to send signal to\n"
1821 " -s --signal=SIGNAL Which signal to send\n"
1822 #if 0 /// UNNEEDED by elogind
1823 " -n --lines=INTEGER Number of journal entries to show\n"
1824 " -o --output=STRING Change journal output mode (short, short-monotonic,\n"
1825 " verbose, export, json, json-pretty, json-sse, cat)\n\n"
1827 " -c Cancel a pending shutdown\n"
1828 " -i --ignore-inhibitors When shutting down or sleeping, ignore inhibitors\n"
1829 "Session Commands:\n"
1830 " list-sessions List sessions\n"
1831 " session-status [ID...] Show session status\n"
1832 " show-session [ID...] Show properties of sessions or the manager\n"
1833 " activate [ID] Activate a session\n"
1834 " lock-session [ID...] Screen lock one or more sessions\n"
1835 " unlock-session [ID...] Screen unlock one or more sessions\n"
1836 " lock-sessions Screen lock all current sessions\n"
1837 " unlock-sessions Screen unlock all current sessions\n"
1838 " terminate-session ID... Terminate one or more sessions\n"
1839 " kill-session ID... Send signal to processes of a session\n\n"
1841 " list-users List users\n"
1842 " user-status [USER...] Show user status\n"
1843 " show-user [USER...] Show properties of users or the manager\n"
1844 " enable-linger [USER...] Enable linger state of one or more users\n"
1845 " disable-linger [USER...] Disable linger state of one or more users\n"
1846 " terminate-user USER... Terminate all sessions of one or more users\n"
1847 " kill-user USER... Send signal to processes of a user\n\n"
1849 " list-seats List seats\n"
1850 " seat-status [NAME...] Show seat status\n"
1851 " show-seat [NAME...] Show properties of seats or the manager\n"
1852 " attach NAME DEVICE... Attach one or more devices to a seat\n"
1853 " flush-devices Flush all device associations\n"
1854 " terminate-seat NAME... Terminate all sessions on one or more seats\n"
1855 "System Commands:\n"
1856 " poweroff Turn off the machine\n"
1857 " reboot Reboot the machine\n"
1858 " suspend Suspend the machine to memory\n"
1859 " hibernate Suspend the machine to disk\n"
1860 " hybrid-sleep Suspend the machine to memory and disk\n"
1861 , program_invocation_short_name);
1866 static int parse_argv(int argc, char *argv[]) {
1869 ARG_VERSION = 0x100,
1875 ARG_NO_ASK_PASSWORD,
1878 static const struct option options[] = {
1879 { "help", no_argument, NULL, 'h' },
1880 { "version", no_argument, NULL, ARG_VERSION },
1881 { "property", required_argument, NULL, 'p' },
1882 { "all", no_argument, NULL, 'a' },
1883 { "value", no_argument, NULL, ARG_VALUE },
1884 { "full", no_argument, NULL, 'l' },
1885 { "no-pager", no_argument, NULL, ARG_NO_PAGER },
1886 { "no-wall", no_argument, NULL, ARG_NO_WALL },
1887 { "no-legend", no_argument, NULL, ARG_NO_LEGEND },
1888 { "kill-who", required_argument, NULL, ARG_KILL_WHO },
1889 { "signal", required_argument, NULL, 's' },
1890 { "host", required_argument, NULL, 'H' },
1891 { "machine", required_argument, NULL, 'M' },
1892 { "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
1893 #if 0 /// UNNEEDED by elogind
1894 { "lines", required_argument, NULL, 'n' },
1895 { "output", required_argument, NULL, 'o' },
1897 { "ignore-inhibitors", no_argument, NULL, 'i' },
1906 while ((c = getopt_long(argc, argv, "hp:als:H:M:n:o:ci", options, NULL)) >= 0) {
1911 help(0, NULL, NULL);
1918 r = strv_extend(&arg_property, optarg);
1922 /* If the user asked for a particular
1923 * property, show it to him, even if it is
1941 #if 0 /// UNNEEDED by elogind
1943 if (safe_atou(optarg, &arg_lines) < 0) {
1944 log_error("Failed to parse lines '%s'", optarg);
1950 arg_output = output_mode_from_string(optarg);
1951 if (arg_output < 0) {
1952 log_error("Unknown output '%s'.", optarg);
1959 arg_no_pager = true;
1970 case ARG_NO_ASK_PASSWORD:
1971 arg_ask_password = false;
1975 arg_kill_who = optarg;
1979 arg_signal = signal_from_string_try_harder(optarg);
1980 if (arg_signal < 0) {
1981 log_error("Failed to parse signal string %s.", optarg);
1987 arg_transport = BUS_TRANSPORT_REMOTE;
1992 arg_transport = BUS_TRANSPORT_MACHINE;
1997 arg_action = ACTION_CANCEL_SHUTDOWN;
2001 arg_ignore_inhibitors = true;
2008 assert_not_reached("Unhandled option");
2015 static int loginctl_main(int argc, char *argv[], sd_bus *bus) {
2017 static const Verb verbs[] = {
2018 { "help", VERB_ANY, VERB_ANY, 0, help },
2019 { "list-sessions", VERB_ANY, 1, VERB_DEFAULT, list_sessions },
2020 { "session-status", VERB_ANY, VERB_ANY, 0, show_session },
2021 { "show-session", VERB_ANY, VERB_ANY, 0, show_session },
2022 { "activate", VERB_ANY, 2, 0, activate },
2023 { "lock-session", VERB_ANY, VERB_ANY, 0, activate },
2024 { "unlock-session", VERB_ANY, VERB_ANY, 0, activate },
2025 { "lock-sessions", VERB_ANY, 1, 0, lock_sessions },
2026 { "unlock-sessions", VERB_ANY, 1, 0, lock_sessions },
2027 { "terminate-session", 2, VERB_ANY, 0, activate },
2028 { "kill-session", 2, VERB_ANY, 0, kill_session },
2029 { "list-users", VERB_ANY, 1, 0, list_users },
2030 { "user-status", VERB_ANY, VERB_ANY, 0, show_user },
2031 { "show-user", VERB_ANY, VERB_ANY, 0, show_user },
2032 { "enable-linger", VERB_ANY, VERB_ANY, 0, enable_linger },
2033 { "disable-linger", VERB_ANY, VERB_ANY, 0, enable_linger },
2034 { "terminate-user", 2, VERB_ANY, 0, terminate_user },
2035 { "kill-user", 2, VERB_ANY, 0, kill_user },
2036 { "list-seats", VERB_ANY, 1, 0, list_seats },
2037 { "seat-status", VERB_ANY, VERB_ANY, 0, show_seat },
2038 { "show-seat", VERB_ANY, VERB_ANY, 0, show_seat },
2039 { "attach", 3, VERB_ANY, 0, attach },
2040 { "flush-devices", VERB_ANY, 1, 0, flush_devices },
2041 { "terminate-seat", 2, VERB_ANY, 0, terminate_seat },
2042 { "poweroff", VERB_ANY, VERB_ANY, 0, start_special },
2043 { "reboot", VERB_ANY, VERB_ANY, 0, start_special },
2044 { "suspend", VERB_ANY, 1, 0, start_special },
2045 { "hibernate", VERB_ANY, 1, 0, start_special },
2046 { "hybrid-sleep", VERB_ANY, 1, 0, start_special },
2047 { "cancel-shutdown", VERB_ANY, 1, 0, start_special },
2051 if ((argc == optind) && (ACTION_CANCEL_SHUTDOWN == arg_action))
2052 return elogind_cancel_shutdown(bus, ACTION_POWEROFF);
2054 return dispatch_verb(argc, argv, verbs, bus);
2057 int main(int argc, char *argv[]) {
2058 _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
2061 setlocale(LC_ALL, "");
2062 elogind_set_program_name(argv[0]);
2063 log_parse_environment();
2066 r = parse_argv(argc, argv);
2070 r = bus_connect_transport(arg_transport, arg_host, false, &bus);
2072 log_error_errno(r, "Failed to create bus connection: %m");
2076 sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
2077 r = loginctl_main(argc, argv, bus);
2081 polkit_agent_close();
2083 strv_free(arg_property);
2084 strv_free(arg_wall);
2086 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;