1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
8 #include "sd-journal.h"
10 #include "alloc-util.h"
12 #include "bus-error.h"
13 #include "bus-locator.h"
14 #include "bus-map-properties.h"
15 #include "bus-print-properties.h"
16 #include "bus-unit-procs.h"
18 #include "cgroup-show.h"
19 #include "cgroup-util.h"
20 #include "format-table.h"
21 #include "format-util.h"
23 #include "logs-show.h"
24 #include "main-func.h"
26 #include "parse-argument.h"
27 #include "parse-util.h"
28 #include "polkit-agent.h"
29 #include "pretty-print.h"
30 #include "process-util.h"
31 #include "runtime-scope.h"
32 #include "string-table.h"
33 #include "string-util.h"
35 #include "sysfs-show.h"
36 #include "terminal-util.h"
37 #include "time-util.h"
38 #include "user-util.h"
41 static char **arg_property
= NULL
;
42 static BusPrintPropertyFlags arg_print_flags
= 0;
43 static bool arg_full
= false;
44 static PagerFlags arg_pager_flags
= 0;
45 static bool arg_legend
= true;
46 static sd_json_format_flags_t arg_json_format_flags
= SD_JSON_FORMAT_OFF
;
47 static const char *arg_kill_whom
= NULL
;
48 static int arg_signal
= SIGTERM
;
49 static BusTransport arg_transport
= BUS_TRANSPORT_LOCAL
;
50 static const char *arg_host
= NULL
;
51 static bool arg_ask_password
= true;
52 static unsigned arg_lines
= 10;
53 static OutputMode arg_output
= OUTPUT_SHORT
;
55 STATIC_DESTRUCTOR_REGISTER(arg_property
, strv_freep
);
57 typedef struct SessionStatusInfo
{
61 dual_timestamp timestamp
;
67 const char *remote_host
;
68 const char *remote_user
;
77 dual_timestamp idle_hint_timestamp
;
80 typedef struct UserStatusInfo
{
84 dual_timestamp timestamp
;
91 typedef struct SeatStatusInfo
{
93 const char *active_session
;
97 static void user_status_info_done(UserStatusInfo
*info
) {
100 strv_free(info
->sessions
);
103 static void seat_status_info_done(SeatStatusInfo
*info
) {
106 strv_free(info
->sessions
);
109 static OutputFlags
get_output_flags(void) {
111 FLAGS_SET(arg_print_flags
, BUS_PRINT_PROPERTY_SHOW_EMPTY
) * OUTPUT_SHOW_ALL
|
112 (arg_full
|| !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH
|
113 colors_enabled() * OUTPUT_COLOR
;
116 static int list_table_print(Table
*table
, const char *type
) {
122 r
= table_set_sort(table
, (size_t) 0);
124 return table_log_sort_error(r
);
126 r
= table_print_with_pager(table
, arg_json_format_flags
, arg_pager_flags
, arg_legend
);
131 if (table_isempty(table
))
132 printf("No %s.\n", type
);
134 printf("\n%zu %s listed.\n", table_get_rows(table
) - 1, type
);
140 static int list_sessions_table_add(Table
*table
, sd_bus_message
*reply
) {
146 r
= sd_bus_message_enter_container(reply
, 'a', "(sussussbto)");
148 return bus_log_parse_error(r
);
151 const char *session_id
, *user
, *seat
, *class, *tty
;
152 uint32_t uid
, leader_pid
;
154 uint64_t idle_timestamp_monotonic
;
156 r
= sd_bus_message_read(reply
, "(sussussbto)",
165 &idle_timestamp_monotonic
,
166 /* object = */ NULL
);
168 return bus_log_parse_error(r
);
172 r
= table_add_many(table
,
173 TABLE_STRING
, session_id
,
174 TABLE_UID
, (uid_t
) uid
,
176 TABLE_STRING
, empty_to_null(seat
),
177 TABLE_PID
, (pid_t
) leader_pid
,
179 TABLE_STRING
, empty_to_null(tty
),
180 TABLE_BOOLEAN
, idle
);
182 return table_log_add_error(r
);
185 r
= table_add_cell(table
, NULL
, TABLE_TIMESTAMP_RELATIVE_MONOTONIC
, &idle_timestamp_monotonic
);
187 r
= table_add_cell(table
, NULL
, TABLE_EMPTY
, NULL
);
189 return table_log_add_error(r
);
192 r
= sd_bus_message_exit_container(reply
);
194 return bus_log_parse_error(r
);
199 static int list_sessions_table_add_fallback(Table
*table
, sd_bus_message
*reply
, sd_bus
*bus
) {
201 static const struct bus_properties_map map
[] = {
202 { "Leader", "u", NULL
, offsetof(SessionStatusInfo
, leader
) },
203 { "Class", "s", NULL
, offsetof(SessionStatusInfo
, class) },
204 { "TTY", "s", NULL
, offsetof(SessionStatusInfo
, tty
) },
205 { "IdleHint", "b", NULL
, offsetof(SessionStatusInfo
, idle_hint
) },
206 { "IdleSinceHintMonotonic", "t", NULL
, offsetof(SessionStatusInfo
, idle_hint_timestamp
.monotonic
) },
216 r
= sd_bus_message_enter_container(reply
, 'a', "(susso)");
218 return bus_log_parse_error(r
);
221 _cleanup_(sd_bus_error_free
) sd_bus_error e
= SD_BUS_ERROR_NULL
;
222 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
223 const char *id
, *user
, *seat
, *object
;
225 SessionStatusInfo i
= {};
227 r
= sd_bus_message_read(reply
, "(susso)", &id
, &uid
, &user
, &seat
, &object
);
229 return bus_log_parse_error(r
);
233 r
= bus_map_all_properties(bus
, "org.freedesktop.login1", object
, map
, BUS_MAP_BOOLEAN_AS_BOOL
, &e
, &m
, &i
);
235 log_full_errno(sd_bus_error_has_name(&e
, SD_BUS_ERROR_UNKNOWN_OBJECT
) ? LOG_DEBUG
: LOG_WARNING
,
237 "Failed to get properties of session %s, ignoring: %s",
238 id
, bus_error_message(&e
, r
));
242 r
= table_add_many(table
,
244 TABLE_UID
, (uid_t
) uid
,
246 TABLE_STRING
, empty_to_null(seat
),
248 TABLE_STRING
, i
.class,
249 TABLE_STRING
, empty_to_null(i
.tty
),
250 TABLE_BOOLEAN
, i
.idle_hint
);
252 return table_log_add_error(r
);
255 r
= table_add_cell(table
, NULL
, TABLE_TIMESTAMP_RELATIVE_MONOTONIC
, &i
.idle_hint_timestamp
.monotonic
);
257 r
= table_add_cell(table
, NULL
, TABLE_EMPTY
, NULL
);
259 return table_log_add_error(r
);
262 r
= sd_bus_message_exit_container(reply
);
264 return bus_log_parse_error(r
);
269 static int list_sessions(int argc
, char *argv
[], void *userdata
) {
270 sd_bus
*bus
= ASSERT_PTR(userdata
);
271 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
272 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
273 _cleanup_(table_unrefp
) Table
*table
= NULL
;
279 r
= bus_call_method(bus
, bus_login_mgr
, "ListSessionsEx", &error
, &reply
, NULL
);
281 if (sd_bus_error_has_name(&error
, SD_BUS_ERROR_UNKNOWN_METHOD
)) {
282 sd_bus_error_free(&error
);
285 r
= bus_call_method(bus
, bus_login_mgr
, "ListSessions", &error
, &reply
, NULL
);
288 return log_error_errno(r
, "Failed to list sessions: %s", bus_error_message(&error
, r
));
291 table
= table_new("session", "uid", "user", "seat", "leader", "class", "tty", "idle", "since");
295 /* Right-align the first two fields (since they are numeric) */
296 (void) table_set_align_percent(table
, TABLE_HEADER_CELL(0), 100);
297 (void) table_set_align_percent(table
, TABLE_HEADER_CELL(1), 100);
299 (void) table_set_ersatz_string(table
, TABLE_ERSATZ_DASH
);
302 r
= list_sessions_table_add(table
, reply
);
304 r
= list_sessions_table_add_fallback(table
, reply
, bus
);
308 return list_table_print(table
, "sessions");
311 static int list_users(int argc
, char *argv
[], void *userdata
) {
313 static const struct bus_properties_map property_map
[] = {
314 { "Linger", "b", NULL
, offsetof(UserStatusInfo
, linger
) },
315 { "State", "s", NULL
, offsetof(UserStatusInfo
, state
) },
319 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
320 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
321 _cleanup_(table_unrefp
) Table
*table
= NULL
;
322 sd_bus
*bus
= ASSERT_PTR(userdata
);
327 r
= bus_call_method(bus
, bus_login_mgr
, "ListUsers", &error
, &reply
, NULL
);
329 return log_error_errno(r
, "Failed to list users: %s", bus_error_message(&error
, r
));
331 r
= sd_bus_message_enter_container(reply
, 'a', "(uso)");
333 return bus_log_parse_error(r
);
335 table
= table_new("uid", "user", "linger", "state");
339 (void) table_set_align_percent(table
, TABLE_HEADER_CELL(0), 100);
340 (void) table_set_ersatz_string(table
, TABLE_ERSATZ_DASH
);
343 _cleanup_(sd_bus_error_free
) sd_bus_error error_property
= SD_BUS_ERROR_NULL
;
344 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply_property
= NULL
;
345 _cleanup_(user_status_info_done
) UserStatusInfo info
= {};
346 const char *user
, *object
;
349 r
= sd_bus_message_read(reply
, "(uso)", &uid
, &user
, &object
);
351 return bus_log_parse_error(r
);
355 r
= bus_map_all_properties(bus
,
356 "org.freedesktop.login1",
359 BUS_MAP_BOOLEAN_AS_BOOL
,
364 log_full_errno(sd_bus_error_has_name(&error_property
, SD_BUS_ERROR_UNKNOWN_OBJECT
) ? LOG_DEBUG
: LOG_WARNING
,
366 "Failed to get properties of user %s, ignoring: %s",
367 user
, bus_error_message(&error_property
, r
));
371 r
= table_add_many(table
,
372 TABLE_UID
, (uid_t
) uid
,
374 TABLE_BOOLEAN
, info
.linger
,
375 TABLE_STRING
, info
.state
);
377 return table_log_add_error(r
);
380 r
= sd_bus_message_exit_container(reply
);
382 return bus_log_parse_error(r
);
384 return list_table_print(table
, "users");
387 static int list_seats(int argc
, char *argv
[], void *userdata
) {
388 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
389 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
390 _cleanup_(table_unrefp
) Table
*table
= NULL
;
391 sd_bus
*bus
= ASSERT_PTR(userdata
);
396 r
= bus_call_method(bus
, bus_login_mgr
, "ListSeats", &error
, &reply
, NULL
);
398 return log_error_errno(r
, "Failed to list seats: %s", bus_error_message(&error
, r
));
400 r
= sd_bus_message_enter_container(reply
, 'a', "(so)");
402 return bus_log_parse_error(r
);
404 table
= table_new("seat");
408 (void) table_set_ersatz_string(table
, TABLE_ERSATZ_DASH
);
413 r
= sd_bus_message_read(reply
, "(so)", &seat
, NULL
);
415 return bus_log_parse_error(r
);
419 r
= table_add_cell(table
, NULL
, TABLE_STRING
, seat
);
421 return table_log_add_error(r
);
424 r
= sd_bus_message_exit_container(reply
);
426 return bus_log_parse_error(r
);
428 return list_table_print(table
, "seats");
431 static int show_unit_cgroup(
435 const char *prefix
) {
437 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
438 _cleanup_free_
char *cgroup
= NULL
;
445 r
= show_cgroup_get_unit_path_and_warn(bus
, unit
, &cgroup
);
452 unsigned c
= MAX(LESS_BY(columns(), 18U), 10U);
453 r
= unit_show_processes(bus
, unit
, cgroup
, prefix
, c
, get_output_flags(), &error
);
455 if (arg_transport
== BUS_TRANSPORT_REMOTE
)
458 /* Fallback for older systemd versions where the GetUnitProcesses() call is not yet available */
460 if (cg_is_empty(SYSTEMD_CGROUP_CONTROLLER
, cgroup
) != 0 && leader
<= 0)
463 show_cgroup_and_extra(SYSTEMD_CGROUP_CONTROLLER
, cgroup
, prefix
, c
, &leader
, leader
> 0, get_output_flags());
465 return log_error_errno(r
, "Failed to dump process list: %s", bus_error_message(&error
, r
));
470 static int prop_map_first_of_struct(sd_bus
*bus
, const char *member
, sd_bus_message
*m
, sd_bus_error
*error
, void *userdata
) {
471 const char *contents
;
477 r
= sd_bus_message_peek_type(m
, NULL
, &contents
);
481 r
= sd_bus_message_enter_container(m
, SD_BUS_TYPE_STRUCT
, contents
);
485 r
= sd_bus_message_read_basic(m
, contents
[0], userdata
);
489 r
= sd_bus_message_skip(m
, contents
+1);
493 r
= sd_bus_message_exit_container(m
);
500 static int prop_map_sessions_strv(sd_bus
*bus
, const char *member
, sd_bus_message
*m
, sd_bus_error
*error
, void *userdata
) {
507 r
= sd_bus_message_enter_container(m
, 'a', "(so)");
511 while ((r
= sd_bus_message_read(m
, "(so)", &name
, NULL
)) > 0) {
512 r
= strv_extend(userdata
, name
);
519 return sd_bus_message_exit_container(m
);
522 static int mark_session(char **sessions
, const char *target_session
) {
524 assert(target_session
);
526 STRV_FOREACH(i
, sessions
)
527 if (streq(*i
, target_session
)) {
528 _cleanup_free_
char *marked
= NULL
;
530 marked
= strjoin("*", target_session
);
534 return free_and_replace(*i
, marked
);
540 static int print_session_status_info(sd_bus
*bus
, const char *path
) {
542 static const struct bus_properties_map map
[] = {
543 { "Id", "s", NULL
, offsetof(SessionStatusInfo
, id
) },
544 { "Name", "s", NULL
, offsetof(SessionStatusInfo
, name
) },
545 { "TTY", "s", NULL
, offsetof(SessionStatusInfo
, tty
) },
546 { "Display", "s", NULL
, offsetof(SessionStatusInfo
, display
) },
547 { "RemoteHost", "s", NULL
, offsetof(SessionStatusInfo
, remote_host
) },
548 { "RemoteUser", "s", NULL
, offsetof(SessionStatusInfo
, remote_user
) },
549 { "Service", "s", NULL
, offsetof(SessionStatusInfo
, service
) },
550 { "Desktop", "s", NULL
, offsetof(SessionStatusInfo
, desktop
) },
551 { "Type", "s", NULL
, offsetof(SessionStatusInfo
, type
) },
552 { "Class", "s", NULL
, offsetof(SessionStatusInfo
, class) },
553 { "Scope", "s", NULL
, offsetof(SessionStatusInfo
, scope
) },
554 { "State", "s", NULL
, offsetof(SessionStatusInfo
, state
) },
555 { "VTNr", "u", NULL
, offsetof(SessionStatusInfo
, vtnr
) },
556 { "Leader", "u", NULL
, offsetof(SessionStatusInfo
, leader
) },
557 { "Remote", "b", NULL
, offsetof(SessionStatusInfo
, remote
) },
558 { "Timestamp", "t", NULL
, offsetof(SessionStatusInfo
, timestamp
.realtime
) },
559 { "TimestampMonotonic", "t", NULL
, offsetof(SessionStatusInfo
, timestamp
.monotonic
) },
560 { "IdleHint", "b", NULL
, offsetof(SessionStatusInfo
, idle_hint
) },
561 { "IdleSinceHint", "t", NULL
, offsetof(SessionStatusInfo
, idle_hint_timestamp
.realtime
) },
562 { "IdleSinceHintMonotonic", "t", NULL
, offsetof(SessionStatusInfo
, idle_hint_timestamp
.monotonic
) },
563 { "User", "(uo)", prop_map_first_of_struct
, offsetof(SessionStatusInfo
, uid
) },
564 { "Seat", "(so)", prop_map_first_of_struct
, offsetof(SessionStatusInfo
, seat
) },
568 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
569 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
570 _cleanup_(table_unrefp
) Table
*table
= NULL
;
571 SessionStatusInfo i
= {};
574 r
= bus_map_all_properties(bus
, "org.freedesktop.login1", path
, map
, BUS_MAP_BOOLEAN_AS_BOOL
, &error
, &m
, &i
);
576 return log_error_errno(r
, "Could not get properties: %s", bus_error_message(&error
, r
));
578 table
= table_new_vertical();
582 (void) table_set_ersatz_string(table
, TABLE_ERSATZ_NA
);
584 if (dual_timestamp_is_set(&i
.timestamp
)) {
585 r
= table_add_cell(table
, NULL
, TABLE_FIELD
, "Since");
587 return table_log_add_error(r
);
589 r
= table_add_cell_stringf(table
, NULL
, "%s; %s",
590 FORMAT_TIMESTAMP(i
.timestamp
.realtime
),
591 FORMAT_TIMESTAMP_RELATIVE_MONOTONIC(i
.timestamp
.monotonic
));
593 return table_log_add_error(r
);
596 r
= table_add_many(table
,
597 TABLE_FIELD
, "State",
598 TABLE_STRING
, i
.state
);
600 return table_log_add_error(r
);
603 _cleanup_free_
char *name
= NULL
;
605 (void) pid_get_comm(i
.leader
, &name
);
607 r
= table_add_cell(table
, NULL
, TABLE_FIELD
, "Leader");
609 return table_log_add_error(r
);
611 r
= table_add_cell_stringf(table
, NULL
, PID_FMT
"%s%s%s",
613 !isempty(name
) ? " (" : "",
615 !isempty(name
) ? ")" : "");
617 return table_log_add_error(r
);
620 if (!isempty(i
.seat
)) {
621 r
= table_add_cell(table
, NULL
, TABLE_FIELD
, "Seat");
623 return table_log_add_error(r
);
626 r
= table_add_cell_stringf(table
, NULL
, "%s; vc%u", i
.seat
, i
.vtnr
);
628 r
= table_add_cell(table
, NULL
, TABLE_STRING
, i
.seat
);
630 return table_log_add_error(r
);
634 r
= table_add_many(table
,
636 TABLE_STRING
, i
.tty
);
637 else if (!isempty(i
.display
))
638 r
= table_add_many(table
,
639 TABLE_FIELD
, "Display",
640 TABLE_STRING
, i
.display
);
644 return table_log_add_error(r
);
646 r
= table_add_cell(table
, NULL
, TABLE_FIELD
, "Remote");
648 return table_log_add_error(r
);
650 if (i
.remote_host
&& i
.remote_user
)
651 r
= table_add_cell_stringf(table
, NULL
, "%s@%s", i
.remote_user
, i
.remote_host
);
652 else if (i
.remote_host
)
653 r
= table_add_cell(table
, NULL
, TABLE_STRING
, i
.remote_host
);
654 else if (i
.remote_user
)
655 r
= table_add_cell_stringf(table
, NULL
, "user %s", i
.remote_user
);
657 r
= table_add_cell(table
, NULL
, TABLE_BOOLEAN
, &i
.remote
);
659 return table_log_add_error(r
);
662 r
= table_add_many(table
,
663 TABLE_FIELD
, "Service",
664 TABLE_STRING
, i
.service
);
666 return table_log_add_error(r
);
670 r
= table_add_many(table
,
672 TABLE_STRING
, i
.type
);
674 return table_log_add_error(r
);
678 r
= table_add_many(table
,
679 TABLE_FIELD
, "Class",
680 TABLE_STRING
, i
.class);
682 return table_log_add_error(r
);
685 if (!isempty(i
.desktop
)) {
686 r
= table_add_many(table
,
687 TABLE_FIELD
, "Desktop",
688 TABLE_STRING
, i
.desktop
);
690 return table_log_add_error(r
);
693 r
= table_add_cell(table
, NULL
, TABLE_FIELD
, "Idle");
695 return table_log_add_error(r
);
697 if (i
.idle_hint
&& dual_timestamp_is_set(&i
.idle_hint_timestamp
))
698 r
= table_add_cell_stringf(table
, NULL
, "%s since %s (%s)",
700 FORMAT_TIMESTAMP(i
.idle_hint_timestamp
.realtime
),
701 FORMAT_TIMESTAMP_RELATIVE_MONOTONIC(i
.idle_hint_timestamp
.monotonic
));
703 r
= table_add_cell(table
, NULL
, TABLE_BOOLEAN
, &i
.idle_hint
);
705 return table_log_add_error(r
);
708 r
= table_add_many(table
,
710 TABLE_SET_MINIMUM_WIDTH
, STRLEN("Display"), /* For alignment with show_unit_cgroup */
711 TABLE_STRING
, i
.scope
);
713 return table_log_add_error(r
);
716 /* We don't use the table to show the header, in order to make the width of the column stable. */
717 printf("%s%s - %s (" UID_FMT
")%s\n", ansi_highlight(), i
.id
, i
.name
, i
.uid
, ansi_normal());
719 r
= table_print(table
, NULL
);
721 return table_log_print_error(r
);
724 show_unit_cgroup(bus
, i
.scope
, i
.leader
, /* prefix = */ strrepa(" ", STRLEN("Display: ")));
726 if (arg_transport
== BUS_TRANSPORT_LOCAL
)
727 show_journal_by_unit(
730 /* namespace = */ NULL
,
733 i
.timestamp
.monotonic
,
735 get_output_flags() | OUTPUT_BEGIN_NEWLINE
,
736 SD_JOURNAL_LOCAL_ONLY
,
737 /* system_unit = */ true,
738 /* ellipsized = */ NULL
);
744 static int print_user_status_info(sd_bus
*bus
, const char *path
) {
746 static const struct bus_properties_map map
[] = {
747 { "Name", "s", NULL
, offsetof(UserStatusInfo
, name
) },
748 { "Linger", "b", NULL
, offsetof(UserStatusInfo
, linger
) },
749 { "Slice", "s", NULL
, offsetof(UserStatusInfo
, slice
) },
750 { "State", "s", NULL
, offsetof(UserStatusInfo
, state
) },
751 { "UID", "u", NULL
, offsetof(UserStatusInfo
, uid
) },
752 { "Timestamp", "t", NULL
, offsetof(UserStatusInfo
, timestamp
.realtime
) },
753 { "TimestampMonotonic", "t", NULL
, offsetof(UserStatusInfo
, timestamp
.monotonic
) },
754 { "Display", "(so)", prop_map_first_of_struct
, offsetof(UserStatusInfo
, display
) },
755 { "Sessions", "a(so)", prop_map_sessions_strv
, offsetof(UserStatusInfo
, sessions
) },
759 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
760 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
761 _cleanup_(user_status_info_done
) UserStatusInfo i
= {};
762 _cleanup_(table_unrefp
) Table
*table
= NULL
;
765 r
= bus_map_all_properties(bus
, "org.freedesktop.login1", path
, map
, BUS_MAP_BOOLEAN_AS_BOOL
, &error
, &m
, &i
);
767 return log_error_errno(r
, "Could not get properties: %s", bus_error_message(&error
, r
));
769 table
= table_new_vertical();
773 (void) table_set_ersatz_string(table
, TABLE_ERSATZ_NA
);
775 if (dual_timestamp_is_set(&i
.timestamp
)) {
776 r
= table_add_cell(table
, NULL
, TABLE_FIELD
, "Since");
778 return table_log_add_error(r
);
780 r
= table_add_cell_stringf(table
, NULL
, "%s; %s",
781 FORMAT_TIMESTAMP(i
.timestamp
.realtime
),
782 FORMAT_TIMESTAMP_RELATIVE_MONOTONIC(i
.timestamp
.monotonic
));
784 return table_log_add_error(r
);
787 r
= table_add_many(table
,
788 TABLE_FIELD
, "State",
789 TABLE_STRING
, i
.state
);
791 return table_log_add_error(r
);
793 if (!strv_isempty(i
.sessions
)) {
794 _cleanup_strv_free_
char **sessions
= TAKE_PTR(i
.sessions
);
796 r
= mark_session(sessions
, i
.display
);
800 r
= table_add_many(table
,
801 TABLE_FIELD
, "Sessions",
802 TABLE_STRV_WRAPPED
, sessions
);
804 return table_log_add_error(r
);
807 r
= table_add_many(table
,
808 TABLE_FIELD
, "Linger",
809 TABLE_BOOLEAN
, i
.linger
);
811 return table_log_add_error(r
);
814 r
= table_add_many(table
,
816 TABLE_SET_MINIMUM_WIDTH
, STRLEN("Sessions"), /* For alignment with show_unit_cgroup */
817 TABLE_STRING
, i
.slice
);
819 return table_log_add_error(r
);
822 printf("%s%s (" UID_FMT
")%s\n", ansi_highlight(), i
.name
, i
.uid
, ansi_normal());
824 r
= table_print(table
, NULL
);
826 return table_log_print_error(r
);
829 show_unit_cgroup(bus
, i
.slice
, /* leader = */ 0, /* prefix = */ strrepa(" ", STRLEN("Sessions: ")));
831 if (arg_transport
== BUS_TRANSPORT_LOCAL
)
832 show_journal_by_unit(
835 /* namespace = */ NULL
,
838 i
.timestamp
.monotonic
,
840 get_output_flags() | OUTPUT_BEGIN_NEWLINE
,
841 SD_JOURNAL_LOCAL_ONLY
,
842 /* system_unit = */ true,
843 /* ellipsized = */ NULL
);
849 static int print_seat_status_info(sd_bus
*bus
, const char *path
) {
851 static const struct bus_properties_map map
[] = {
852 { "Id", "s", NULL
, offsetof(SeatStatusInfo
, id
) },
853 { "ActiveSession", "(so)", prop_map_first_of_struct
, offsetof(SeatStatusInfo
, active_session
) },
854 { "Sessions", "a(so)", prop_map_sessions_strv
, offsetof(SeatStatusInfo
, sessions
) },
858 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
859 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*m
= NULL
;
860 _cleanup_(seat_status_info_done
) SeatStatusInfo i
= {};
861 _cleanup_(table_unrefp
) Table
*table
= NULL
;
864 r
= bus_map_all_properties(bus
, "org.freedesktop.login1", path
, map
, 0, &error
, &m
, &i
);
866 return log_error_errno(r
, "Could not get properties: %s", bus_error_message(&error
, r
));
868 table
= table_new_vertical();
872 (void) table_set_ersatz_string(table
, TABLE_ERSATZ_NA
);
874 if (!strv_isempty(i
.sessions
)) {
875 _cleanup_strv_free_
char **sessions
= TAKE_PTR(i
.sessions
);
877 r
= mark_session(sessions
, i
.active_session
);
881 r
= table_add_many(table
,
882 TABLE_FIELD
, "Sessions",
883 TABLE_STRV_WRAPPED
, sessions
);
885 return table_log_add_error(r
);
888 if (arg_transport
== BUS_TRANSPORT_LOCAL
) {
889 r
= table_add_many(table
,
890 TABLE_FIELD
, "Devices",
891 TABLE_SET_MINIMUM_WIDTH
, STRLEN("Sessions"), /* For alignment with show_sysfs */
894 return table_log_add_error(r
);
897 printf("%s%s%s\n", ansi_highlight(), i
.id
, ansi_normal());
899 r
= table_print(table
, NULL
);
901 return table_log_print_error(r
);
903 if (arg_transport
== BUS_TRANSPORT_LOCAL
) {
904 unsigned c
= MAX(LESS_BY(columns(), 21U), 10U);
905 show_sysfs(i
.id
, strrepa(" ", STRLEN("Sessions:")), c
, get_output_flags());
911 static int print_property(const char *name
, const char *expected_value
, sd_bus_message
*m
, BusPrintPropertyFlags flags
) {
913 const char *contents
;
919 r
= sd_bus_message_peek_type(m
, &type
, &contents
);
925 case SD_BUS_TYPE_STRUCT
:
927 if (contents
[0] == SD_BUS_TYPE_STRING
&& STR_IN_SET(name
, "Display", "Seat", "ActiveSession")) {
930 r
= sd_bus_message_read(m
, "(so)", &s
, NULL
);
932 return bus_log_parse_error(r
);
934 bus_print_property_value(name
, expected_value
, flags
, s
);
938 } else if (contents
[0] == SD_BUS_TYPE_UINT32
&& streq(name
, "User")) {
941 r
= sd_bus_message_read(m
, "(uo)", &uid
, NULL
);
943 return bus_log_parse_error(r
);
945 if (!uid_is_valid(uid
))
946 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
947 "Invalid user ID: " UID_FMT
,
950 bus_print_property_valuef(name
, expected_value
, flags
, UID_FMT
, uid
);
955 case SD_BUS_TYPE_ARRAY
:
957 if (contents
[0] == SD_BUS_TYPE_STRUCT_BEGIN
&& streq(name
, "Sessions")) {
961 r
= sd_bus_message_enter_container(m
, SD_BUS_TYPE_ARRAY
, "(so)");
963 return bus_log_parse_error(r
);
965 if (!FLAGS_SET(flags
, BUS_PRINT_PROPERTY_ONLY_VALUE
))
968 while ((r
= sd_bus_message_read(m
, "(so)", &s
, NULL
)) > 0) {
969 printf("%s%s", space
? " " : "", s
);
973 if (space
|| !FLAGS_SET(flags
, BUS_PRINT_PROPERTY_ONLY_VALUE
))
977 return bus_log_parse_error(r
);
979 r
= sd_bus_message_exit_container(m
);
981 return bus_log_parse_error(r
);
991 static int show_properties(sd_bus
*bus
, const char *path
) {
997 r
= bus_print_all_properties(
999 "org.freedesktop.login1",
1006 return bus_log_parse_error(r
);
1011 static int get_bus_path_by_id(
1018 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1019 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1025 assert(STR_IN_SET(type
, "session", "seat"));
1030 r
= bus_call_method(bus
, bus_login_mgr
, method
, &error
, &reply
, "s", id
);
1032 return log_error_errno(r
, "Failed to get path for %s '%s': %s", type
, id
, bus_error_message(&error
, r
));
1034 r
= sd_bus_message_read(reply
, "o", &path
);
1036 return bus_log_parse_error(r
);
1038 return strdup_to(ret
, path
);
1041 static int show_session(int argc
, char *argv
[], void *userdata
) {
1042 sd_bus
*bus
= ASSERT_PTR(userdata
);
1048 properties
= !strstr(argv
[0], "status");
1050 pager_open(arg_pager_flags
);
1053 _cleanup_free_
char *path
= NULL
;
1055 /* If no argument is specified inspect the manager itself */
1057 return show_properties(bus
, "/org/freedesktop/login1");
1059 r
= get_bus_path_by_id(bus
, "session", "GetSession", "auto", &path
);
1063 return print_session_status_info(bus
, path
);
1066 for (int i
= 1, first
= true; i
< argc
; i
++, first
= false) {
1067 _cleanup_free_
char *path
= NULL
;
1069 r
= get_bus_path_by_id(bus
, "session", "GetSession", argv
[i
], &path
);
1077 r
= show_properties(bus
, path
);
1079 r
= print_session_status_info(bus
, path
);
1087 static int show_user(int argc
, char *argv
[], void *userdata
) {
1088 sd_bus
*bus
= ASSERT_PTR(userdata
);
1094 properties
= !strstr(argv
[0], "status");
1096 pager_open(arg_pager_flags
);
1099 /* If no argument is specified inspect the manager itself */
1101 return show_properties(bus
, "/org/freedesktop/login1");
1103 return print_user_status_info(bus
, "/org/freedesktop/login1/user/self");
1106 for (int i
= 1, first
= true; i
< argc
; i
++, first
= false) {
1107 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1108 _cleanup_(sd_bus_message_unrefp
) sd_bus_message
*reply
= NULL
;
1112 r
= get_user_creds((const char**) (argv
+i
), &uid
, NULL
, NULL
, NULL
, 0);
1114 return log_error_errno(r
, "Failed to look up user %s: %m", argv
[i
]);
1116 r
= bus_call_method(bus
, bus_login_mgr
, "GetUser", &error
, &reply
, "u", (uint32_t) uid
);
1118 return log_error_errno(r
, "Failed to get user: %s", bus_error_message(&error
, r
));
1120 r
= sd_bus_message_read(reply
, "o", &path
);
1122 return bus_log_parse_error(r
);
1128 r
= show_properties(bus
, path
);
1130 r
= print_user_status_info(bus
, path
);
1138 static int show_seat(int argc
, char *argv
[], void *userdata
) {
1139 sd_bus
*bus
= ASSERT_PTR(userdata
);
1145 properties
= !strstr(argv
[0], "status");
1147 pager_open(arg_pager_flags
);
1150 _cleanup_free_
char *path
= NULL
;
1152 /* If no argument is specified inspect the manager itself */
1154 return show_properties(bus
, "/org/freedesktop/login1");
1156 r
= get_bus_path_by_id(bus
, "seat", "GetSeat", "auto", &path
);
1160 return print_seat_status_info(bus
, path
);
1163 for (int i
= 1, first
= true; i
< argc
; i
++, first
= false) {
1164 _cleanup_free_
char *path
= NULL
;
1166 r
= get_bus_path_by_id(bus
, "seat", "GetSeat", argv
[i
], &path
);
1174 r
= show_properties(bus
, path
);
1176 r
= print_seat_status_info(bus
, path
);
1184 static int activate(int argc
, char *argv
[], void *userdata
) {
1185 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1186 sd_bus
*bus
= ASSERT_PTR(userdata
);
1191 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1194 r
= sd_bus_call_method(
1196 "org.freedesktop.login1",
1197 "/org/freedesktop/login1/session/auto",
1198 "org.freedesktop.login1.Session",
1199 streq(argv
[0], "lock-session") ? "Lock" :
1200 streq(argv
[0], "unlock-session") ? "Unlock" :
1201 streq(argv
[0], "terminate-session") ? "Terminate" :
1203 &error
, NULL
, NULL
);
1205 return log_error_errno(r
, "Failed to issue method call: %s", bus_error_message(&error
, r
));
1210 for (int i
= 1; i
< argc
; i
++) {
1211 r
= bus_call_method(
1214 streq(argv
[0], "lock-session") ? "LockSession" :
1215 streq(argv
[0], "unlock-session") ? "UnlockSession" :
1216 streq(argv
[0], "terminate-session") ? "TerminateSession" :
1221 return log_error_errno(r
, "Failed to issue method call: %s", bus_error_message(&error
, r
));
1227 static int kill_session(int argc
, char *argv
[], void *userdata
) {
1228 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1229 sd_bus
*bus
= ASSERT_PTR(userdata
);
1234 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1237 arg_kill_whom
= "all";
1239 for (int i
= 1; i
< argc
; i
++) {
1240 r
= bus_call_method(
1245 "ssi", argv
[i
], arg_kill_whom
, arg_signal
);
1247 return log_error_errno(r
, "Could not kill session: %s", bus_error_message(&error
, r
));
1253 static int enable_linger(int argc
, char *argv
[], void *userdata
) {
1254 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1255 sd_bus
*bus
= ASSERT_PTR(userdata
);
1256 char* short_argv
[3];
1262 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1264 b
= streq(argv
[0], "enable-linger");
1267 /* No argument? Let's use an empty user name,
1268 * then logind will use our user. */
1270 short_argv
[0] = argv
[0];
1271 short_argv
[1] = (char*) "";
1272 short_argv
[2] = NULL
;
1277 for (int i
= 1; i
< argc
; i
++) {
1280 if (isempty(argv
[i
]))
1283 r
= get_user_creds((const char**) (argv
+i
), &uid
, NULL
, NULL
, NULL
, 0);
1285 return log_error_errno(r
, "Failed to look up user %s: %m", argv
[i
]);
1288 r
= bus_call_method(
1293 "ubb", (uint32_t) uid
, b
, true);
1295 return log_error_errno(r
, "Could not enable linger: %s", bus_error_message(&error
, r
));
1301 static int terminate_user(int argc
, char *argv
[], void *userdata
) {
1302 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1303 sd_bus
*bus
= ASSERT_PTR(userdata
);
1308 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1310 for (int i
= 1; i
< argc
; i
++) {
1313 if (isempty(argv
[i
]))
1316 const char *u
= argv
[i
];
1318 r
= get_user_creds(&u
, &uid
, NULL
, NULL
, NULL
, 0);
1320 return log_error_errno(r
, "Failed to look up user %s: %m", argv
[i
]);
1323 r
= bus_call_method(bus
, bus_login_mgr
, "TerminateUser", &error
, NULL
, "u", (uint32_t) uid
);
1325 return log_error_errno(r
, "Could not terminate user: %s", bus_error_message(&error
, r
));
1331 static int kill_user(int argc
, char *argv
[], void *userdata
) {
1332 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1333 sd_bus
*bus
= ASSERT_PTR(userdata
);
1338 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1341 arg_kill_whom
= "all";
1343 for (int i
= 1; i
< argc
; i
++) {
1346 if (isempty(argv
[i
]))
1349 const char *u
= argv
[i
];
1351 r
= get_user_creds(&u
, &uid
, NULL
, NULL
, NULL
, 0);
1353 return log_error_errno(r
, "Failed to look up user %s: %m", argv
[i
]);
1356 r
= bus_call_method(
1361 "ui", (uint32_t) uid
, arg_signal
);
1363 return log_error_errno(r
, "Could not kill user: %s", bus_error_message(&error
, r
));
1369 static int attach(int argc
, char *argv
[], void *userdata
) {
1370 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1371 sd_bus
*bus
= ASSERT_PTR(userdata
);
1376 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1378 for (int i
= 2; i
< argc
; i
++) {
1380 r
= bus_call_method(
1385 "ssb", argv
[1], argv
[i
], true);
1387 return log_error_errno(r
, "Could not attach device: %s", bus_error_message(&error
, r
));
1393 static int flush_devices(int argc
, char *argv
[], void *userdata
) {
1394 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1395 sd_bus
*bus
= ASSERT_PTR(userdata
);
1400 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1402 r
= bus_call_method(bus
, bus_login_mgr
, "FlushDevices", &error
, NULL
, "b", true);
1404 return log_error_errno(r
, "Could not flush devices: %s", bus_error_message(&error
, r
));
1409 static int lock_sessions(int argc
, char *argv
[], void *userdata
) {
1410 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1411 sd_bus
*bus
= ASSERT_PTR(userdata
);
1416 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1418 r
= bus_call_method(
1421 streq(argv
[0], "lock-sessions") ? "LockSessions" : "UnlockSessions",
1425 return log_error_errno(r
, "Could not lock sessions: %s", bus_error_message(&error
, r
));
1430 static int terminate_seat(int argc
, char *argv
[], void *userdata
) {
1431 _cleanup_(sd_bus_error_free
) sd_bus_error error
= SD_BUS_ERROR_NULL
;
1432 sd_bus
*bus
= ASSERT_PTR(userdata
);
1437 (void) polkit_agent_open_if_enabled(arg_transport
, arg_ask_password
);
1439 for (int i
= 1; i
< argc
; i
++) {
1441 r
= bus_call_method(bus
, bus_login_mgr
, "TerminateSeat", &error
, NULL
, "s", argv
[i
]);
1443 return log_error_errno(r
, "Could not terminate seat: %s", bus_error_message(&error
, r
));
1449 static int help(int argc
, char *argv
[], void *userdata
) {
1450 _cleanup_free_
char *link
= NULL
;
1453 pager_open(arg_pager_flags
);
1455 r
= terminal_urlify_man("loginctl", "1", &link
);
1459 printf("%1$s [OPTIONS...] COMMAND ...\n\n"
1460 "%5$sSend control commands to or query the login manager.%6$s\n"
1461 "\n%3$sSession Commands:%4$s\n"
1462 " list-sessions List sessions\n"
1463 " session-status [ID...] Show session status\n"
1464 " show-session [ID...] Show properties of sessions or the manager\n"
1465 " activate [ID] Activate a session\n"
1466 " lock-session [ID...] Screen lock one or more sessions\n"
1467 " unlock-session [ID...] Screen unlock one or more sessions\n"
1468 " lock-sessions Screen lock all current sessions\n"
1469 " unlock-sessions Screen unlock all current sessions\n"
1470 " terminate-session ID... Terminate one or more sessions\n"
1471 " kill-session ID... Send signal to processes of a session\n"
1472 "\n%3$sUser Commands:%4$s\n"
1473 " list-users List users\n"
1474 " user-status [USER...] Show user status\n"
1475 " show-user [USER...] Show properties of users or the manager\n"
1476 " enable-linger [USER...] Enable linger state of one or more users\n"
1477 " disable-linger [USER...] Disable linger state of one or more users\n"
1478 " terminate-user USER... Terminate all sessions of one or more users\n"
1479 " kill-user USER... Send signal to processes of a user\n"
1480 "\n%3$sSeat Commands:%4$s\n"
1481 " list-seats List seats\n"
1482 " seat-status [NAME...] Show seat status\n"
1483 " show-seat [NAME...] Show properties of seats or the manager\n"
1484 " attach NAME DEVICE... Attach one or more devices to a seat\n"
1485 " flush-devices Flush all device associations\n"
1486 " terminate-seat NAME... Terminate all sessions on one or more seats\n"
1487 "\n%3$sOptions:%4$s\n"
1488 " -h --help Show this help\n"
1489 " --version Show package version\n"
1490 " --no-pager Do not pipe output into a pager\n"
1491 " --no-legend Do not show the headers and footers\n"
1492 " --no-ask-password Don't prompt for password\n"
1493 " -H --host=[USER@]HOST Operate on remote host\n"
1494 " -M --machine=CONTAINER Operate on local container\n"
1495 " -p --property=NAME Show only properties by this name\n"
1496 " -P NAME Equivalent to --value --property=NAME\n"
1497 " -a --all Show all properties, including empty ones\n"
1498 " --value When showing properties, only print the value\n"
1499 " -l --full Do not ellipsize output\n"
1500 " --kill-whom=WHOM Whom to send signal to\n"
1501 " -s --signal=SIGNAL Which signal to send\n"
1502 " -n --lines=INTEGER Number of journal entries to show\n"
1503 " --json=MODE Generate JSON output for list-sessions/users/seats\n"
1504 " (takes one of pretty, short, or off)\n"
1505 " -j Same as --json=pretty on tty, --json=short otherwise\n"
1506 " -o --output=MODE Change journal output mode (short, short-precise,\n"
1507 " short-iso, short-iso-precise, short-full,\n"
1508 " short-monotonic, short-unix, short-delta,\n"
1509 " json, json-pretty, json-sse, json-seq, cat,\n"
1510 " verbose, export, with-unit)\n"
1511 "\nSee the %2$s for details.\n",
1512 program_invocation_short_name
,
1522 static int parse_argv(int argc
, char *argv
[]) {
1524 ARG_VERSION
= 0x100,
1530 ARG_NO_ASK_PASSWORD
,
1533 static const struct option options
[] = {
1534 { "help", no_argument
, NULL
, 'h' },
1535 { "version", no_argument
, NULL
, ARG_VERSION
},
1536 { "property", required_argument
, NULL
, 'p' },
1537 { "all", no_argument
, NULL
, 'a' },
1538 { "value", no_argument
, NULL
, ARG_VALUE
},
1539 { "full", no_argument
, NULL
, 'l' },
1540 { "no-pager", no_argument
, NULL
, ARG_NO_PAGER
},
1541 { "no-legend", no_argument
, NULL
, ARG_NO_LEGEND
},
1542 { "json", required_argument
, NULL
, ARG_JSON
},
1543 { "kill-whom", required_argument
, NULL
, ARG_KILL_WHOM
},
1544 { "signal", required_argument
, NULL
, 's' },
1545 { "host", required_argument
, NULL
, 'H' },
1546 { "machine", required_argument
, NULL
, 'M' },
1547 { "no-ask-password", no_argument
, NULL
, ARG_NO_ASK_PASSWORD
},
1548 { "lines", required_argument
, NULL
, 'n' },
1549 { "output", required_argument
, NULL
, 'o' },
1558 while ((c
= getopt_long(argc
, argv
, "hp:P:als:H:M:n:o:j", options
, NULL
)) >= 0)
1563 return help(0, NULL
, NULL
);
1569 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_ONLY_VALUE
, true);
1573 r
= strv_extend(&arg_property
, optarg
);
1577 /* If the user asked for a particular
1578 * property, show it to them, even if it is
1580 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_SHOW_EMPTY
, true);
1585 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_SHOW_EMPTY
, true);
1589 SET_FLAG(arg_print_flags
, BUS_PRINT_PROPERTY_ONLY_VALUE
, true);
1597 if (safe_atou(optarg
, &arg_lines
) < 0)
1598 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
1599 "Failed to parse lines '%s'", optarg
);
1603 if (streq(optarg
, "help")) {
1604 DUMP_STRING_TABLE(output_mode
, OutputMode
, _OUTPUT_MODE_MAX
);
1608 arg_output
= output_mode_from_string(optarg
);
1610 return log_error_errno(arg_output
, "Unknown output '%s'.", optarg
);
1615 arg_json_format_flags
= SD_JSON_FORMAT_PRETTY_AUTO
|SD_JSON_FORMAT_COLOR_AUTO
;
1620 r
= parse_json_argument(optarg
, &arg_json_format_flags
);
1624 if (sd_json_format_enabled(arg_json_format_flags
))
1630 arg_pager_flags
|= PAGER_DISABLE
;
1637 case ARG_NO_ASK_PASSWORD
:
1638 arg_ask_password
= false;
1642 arg_kill_whom
= optarg
;
1646 r
= parse_signal_argument(optarg
, &arg_signal
);
1652 arg_transport
= BUS_TRANSPORT_REMOTE
;
1657 r
= parse_machine_argument(optarg
, &arg_host
, &arg_transport
);
1666 assert_not_reached();
1672 static int loginctl_main(int argc
, char *argv
[], sd_bus
*bus
) {
1673 static const Verb verbs
[] = {
1674 { "help", VERB_ANY
, VERB_ANY
, 0, help
},
1675 { "list-sessions", VERB_ANY
, 1, VERB_DEFAULT
, list_sessions
},
1676 { "session-status", VERB_ANY
, VERB_ANY
, 0, show_session
},
1677 { "show-session", VERB_ANY
, VERB_ANY
, 0, show_session
},
1678 { "activate", VERB_ANY
, 2, 0, activate
},
1679 { "lock-session", VERB_ANY
, VERB_ANY
, 0, activate
},
1680 { "unlock-session", VERB_ANY
, VERB_ANY
, 0, activate
},
1681 { "lock-sessions", VERB_ANY
, 1, 0, lock_sessions
},
1682 { "unlock-sessions", VERB_ANY
, 1, 0, lock_sessions
},
1683 { "terminate-session", 2, VERB_ANY
, 0, activate
},
1684 { "kill-session", 2, VERB_ANY
, 0, kill_session
},
1685 { "list-users", VERB_ANY
, 1, 0, list_users
},
1686 { "user-status", VERB_ANY
, VERB_ANY
, 0, show_user
},
1687 { "show-user", VERB_ANY
, VERB_ANY
, 0, show_user
},
1688 { "enable-linger", VERB_ANY
, VERB_ANY
, 0, enable_linger
},
1689 { "disable-linger", VERB_ANY
, VERB_ANY
, 0, enable_linger
},
1690 { "terminate-user", 2, VERB_ANY
, 0, terminate_user
},
1691 { "kill-user", 2, VERB_ANY
, 0, kill_user
},
1692 { "list-seats", VERB_ANY
, 1, 0, list_seats
},
1693 { "seat-status", VERB_ANY
, VERB_ANY
, 0, show_seat
},
1694 { "show-seat", VERB_ANY
, VERB_ANY
, 0, show_seat
},
1695 { "attach", 3, VERB_ANY
, 0, attach
},
1696 { "flush-devices", VERB_ANY
, 1, 0, flush_devices
},
1697 { "terminate-seat", 2, VERB_ANY
, 0, terminate_seat
},
1701 return dispatch_verb(argc
, argv
, verbs
, bus
);
1704 static int run(int argc
, char *argv
[]) {
1705 _cleanup_(sd_bus_flush_close_unrefp
) sd_bus
*bus
= NULL
;
1708 setlocale(LC_ALL
, "");
1711 r
= parse_argv(argc
, argv
);
1715 journal_browse_prepare();
1717 r
= bus_connect_transport(arg_transport
, arg_host
, RUNTIME_SCOPE_SYSTEM
, &bus
);
1719 return bus_log_connect_error(r
, arg_transport
, RUNTIME_SCOPE_SYSTEM
);
1721 (void) sd_bus_set_allow_interactive_authorization(bus
, arg_ask_password
);
1723 return loginctl_main(argc
, argv
, bus
);
1726 DEFINE_MAIN_FUNCTION(run
);