-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
+/* SPDX-License-Identifier: LGPL-2.1+ */
#include <errno.h>
#include <getopt.h>
#include "alloc-util.h"
#include "bus-error.h"
+//#include "bus-unit-util.h"
#include "bus-util.h"
//#include "cgroup-show.h"
#include "cgroup-util.h"
+//#include "format-table.h"
#include "log.h"
//#include "logs-show.h"
#include "macro.h"
#include "pager.h"
#include "parse-util.h"
#include "process-util.h"
+#include "sigbus.h"
#include "signal-util.h"
-//#include "spawn-polkit-agent.h"
+#include "spawn-polkit-agent.h"
+//#include "string-table.h"
#include "strv.h"
#include "sysfs-show.h"
#include "terminal-util.h"
extern BusTransport arg_transport;
static char *arg_host = NULL;
extern bool arg_ask_password;
+extern bool arg_dry_run;
+extern bool arg_quiet;
extern bool arg_no_wall;
extern usec_t arg_when;
extern bool arg_ignore_inhibitors;
extern elogind_action arg_action;
#endif // 0
-#if 0 /// UNNEEDED by elogind
-static void polkit_agent_open_if_enabled(void) {
-
- /* Open the polkit agent as a child process if necessary */
-
- if (!arg_ask_password)
- return;
-
- if (arg_transport != BUS_TRANSPORT_LOCAL)
- return;
-
- polkit_agent_open();
-}
-
static OutputFlags get_output_flags(void) {
return
arg_all * OUTPUT_SHOW_ALL |
- arg_full * OUTPUT_FULL_WIDTH |
- (!on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
+ (arg_full || !on_tty() || pager_have()) * OUTPUT_FULL_WIDTH |
colors_enabled() * OUTPUT_COLOR;
}
-#endif // 0
static int get_session_path(sd_bus *bus, const char *session_id, sd_bus_error *error, char **path) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
return 0;
}
+static int show_table(Table *table, const char *word) {
+ int r;
+
+ assert(table);
+ assert(word);
+
+ if (table_get_rows(table) > 1) {
+ r = table_set_sort(table, (size_t) 0, (size_t) -1);
+ if (r < 0)
+ return log_error_errno(r, "Failed to sort table: %m");
+
+ table_set_header(table, arg_legend);
+
+ r = table_print(table, NULL);
+ if (r < 0)
+ return log_error_errno(r, "Failed to show table: %m");
+ }
+
+ if (arg_legend) {
+ if (table_get_rows(table) > 1)
+ printf("\n%zu %s listed.\n", table_get_rows(table) - 1, word);
+ else
+ printf("No %s.\n", word);
+ }
+
+ return 0;
+}
+
static int list_sessions(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
- const char *id, *user, *seat, *object;
+ _cleanup_(table_unrefp) Table *table = NULL;
sd_bus *bus = userdata;
- unsigned k = 0;
- uint32_t uid;
int r;
assert(bus);
assert(argv);
- pager_open(arg_no_pager, false);
+ (void) pager_open(arg_no_pager, false);
r = sd_bus_call_method(
bus,
"org.freedesktop.login1.Manager",
"ListSessions",
&error, &reply,
- "");
- if (r < 0) {
- log_error("Failed to list sessions: %s", bus_error_message(&error, r));
- return r;
- }
+ NULL);
+ if (r < 0)
+ return log_error_errno(r, "Failed to list sessions: %s", bus_error_message(&error, r));
r = sd_bus_message_enter_container(reply, 'a', "(susso)");
if (r < 0)
return bus_log_parse_error(r);
- if (arg_legend)
- printf("%10s %10s %-16s %-16s %-16s\n", "SESSION", "UID", "USER", "SEAT", "TTY");
+ table = table_new("SESSION", "UID", "USER", "SEAT", "TTY");
+ if (!table)
+ return log_oom();
+
+ /* Right-align the first two fields (since they are numeric) */
+ (void) table_set_align_percent(table, TABLE_HEADER_CELL(0), 100);
+ (void) table_set_align_percent(table, TABLE_HEADER_CELL(1), 100);
+
+ for (;;) {
+ _cleanup_(sd_bus_error_free) sd_bus_error error_tty = SD_BUS_ERROR_NULL;
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply_tty = NULL;
+ const char *id, *user, *seat, *object, *tty = NULL;
+ uint32_t uid;
- while ((r = sd_bus_message_read(reply, "(susso)", &id, &uid, &user, &seat, &object)) > 0) {
- _cleanup_(sd_bus_error_free) sd_bus_error error2 = SD_BUS_ERROR_NULL;
- _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply2 = NULL;
- _cleanup_free_ char *path = NULL;
- const char *tty = NULL;
+ r = sd_bus_message_read(reply, "(susso)", &id, &uid, &user, &seat, &object);
+ if (r < 0)
+ return bus_log_parse_error(r);
+ if (r == 0)
+ break;
- r = get_session_path(bus, id, &error2, &path);
+ r = sd_bus_get_property(
+ bus,
+ "org.freedesktop.login1",
+ object,
+ "org.freedesktop.login1.Session",
+ "TTY",
+ &error_tty,
+ &reply_tty,
+ "s");
if (r < 0)
- log_warning("Failed to get session path: %s", bus_error_message(&error, r));
+ log_warning_errno(r, "Failed to get TTY for session %s: %s", id, bus_error_message(&error_tty, r));
else {
- r = sd_bus_get_property(
- bus,
- "org.freedesktop.login1",
- path,
- "org.freedesktop.login1.Session",
- "TTY",
- &error2,
- &reply2,
- "s");
+ r = sd_bus_message_read(reply_tty, "s", &tty);
if (r < 0)
- log_warning("Failed to get TTY for session %s: %s",
- id, bus_error_message(&error2, r));
- else {
- r = sd_bus_message_read(reply2, "s", &tty);
- if (r < 0)
- return bus_log_parse_error(r);
- }
+ return bus_log_parse_error(r);
}
- printf("%10s %10"PRIu32" %-16s %-16s %-16s\n", id, uid, user, seat, strna(tty));
- k++;
+ r = table_add_many(table,
+ TABLE_STRING, id,
+ TABLE_UINT32, uid,
+ TABLE_STRING, user,
+ TABLE_STRING, seat,
+ TABLE_STRING, strna(tty));
+ if (r < 0)
+ return log_error_errno(r, "Failed to add row to table: %m");
}
+
+ r = sd_bus_message_exit_container(reply);
if (r < 0)
return bus_log_parse_error(r);
- if (arg_legend)
- printf("\n%u sessions listed.\n", k);
-
- return 0;
+ return show_table(table, "sessions");
}
static int list_users(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
- const char *user, *object;
+ _cleanup_(table_unrefp) Table *table = NULL;
sd_bus *bus = userdata;
- unsigned k = 0;
- uint32_t uid;
int r;
assert(bus);
assert(argv);
- pager_open(arg_no_pager, false);
+ (void) pager_open(arg_no_pager, false);
r = sd_bus_call_method(
bus,
"org.freedesktop.login1.Manager",
"ListUsers",
&error, &reply,
- "");
- if (r < 0) {
- log_error("Failed to list users: %s", bus_error_message(&error, r));
- return r;
- }
+ NULL);
+ if (r < 0)
+ return log_error_errno(r, "Failed to list users: %s", bus_error_message(&error, r));
r = sd_bus_message_enter_container(reply, 'a', "(uso)");
if (r < 0)
return bus_log_parse_error(r);
- if (arg_legend)
- printf("%10s %-16s\n", "UID", "USER");
+ table = table_new("UID", "USER");
+ if (!table)
+ return log_oom();
+
+ (void) table_set_align_percent(table, TABLE_HEADER_CELL(0), 100);
- while ((r = sd_bus_message_read(reply, "(uso)", &uid, &user, &object)) > 0) {
- printf("%10"PRIu32" %-16s\n", uid, user);
- k++;
+ for (;;) {
+ const char *user;
+ uint32_t uid;
+
+ r = sd_bus_message_read(reply, "(uso)", &uid, &user, NULL);
+ if (r < 0)
+ return bus_log_parse_error(r);
+ if (r == 0)
+ break;
+
+ r = table_add_many(table,
+ TABLE_UINT32, uid,
+ TABLE_STRING, user);
+ if (r < 0)
+ return log_error_errno(r, "Failed to add row to table: %m");
}
+
+ r = sd_bus_message_exit_container(reply);
if (r < 0)
return bus_log_parse_error(r);
- if (arg_legend)
- printf("\n%u users listed.\n", k);
-
- return 0;
+ return show_table(table, "users");
}
static int list_seats(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
- const char *seat, *object;
+ _cleanup_(table_unrefp) Table *table = NULL;
sd_bus *bus = userdata;
- unsigned k = 0;
int r;
assert(bus);
assert(argv);
- pager_open(arg_no_pager, false);
+ (void) pager_open(arg_no_pager, false);
r = sd_bus_call_method(
bus,
"org.freedesktop.login1.Manager",
"ListSeats",
&error, &reply,
- "");
- if (r < 0) {
- log_error("Failed to list seats: %s", bus_error_message(&error, r));
- return r;
- }
+ NULL);
+ if (r < 0)
+ return log_error_errno(r, "Failed to list seats: %s", bus_error_message(&error, r));
r = sd_bus_message_enter_container(reply, 'a', "(so)");
if (r < 0)
return bus_log_parse_error(r);
- if (arg_legend)
- printf("%-16s\n", "SEAT");
+ table = table_new("SEAT");
+ if (!table)
+ return log_oom();
+
+ for (;;) {
+ const char *seat;
- while ((r = sd_bus_message_read(reply, "(so)", &seat, &object)) > 0) {
- printf("%-16s\n", seat);
- k++;
+ r = sd_bus_message_read(reply, "(so)", &seat, NULL);
+ if (r < 0)
+ return bus_log_parse_error(r);
+ if (r == 0)
+ break;
+
+ r = table_add_cell(table, NULL, TABLE_STRING, seat);
+ if (r < 0)
+ return log_error_errno(r, "Failed to add row to table: %m");
}
+
+ r = sd_bus_message_exit_container(reply);
if (r < 0)
return bus_log_parse_error(r);
- if (arg_legend)
- printf("\n%u seats listed.\n", k);
-
- return 0;
+ return show_table(table, "seats");
}
#if 0 /// UNNEEDED by elogind
static int show_unit_cgroup(sd_bus *bus, const char *interface, const char *unit, pid_t leader) {
+ _cleanup_free_ char *cgroup = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
- _cleanup_free_ char *path = NULL;
- const char *cgroup;
unsigned c;
int r;
assert(bus);
assert(unit);
- path = unit_dbus_path_from_name(unit);
- if (!path)
- return log_oom();
-
- r = sd_bus_get_property(
- bus,
- "org.freedesktop.systemd1",
- path,
- interface,
- "ControlGroup",
- &error,
- &reply,
- "s");
- if (r < 0)
- return log_error_errno(r, "Failed to query ControlGroup: %s", bus_error_message(&error, r));
-
- r = sd_bus_message_read(reply, "s", &cgroup);
+ r = show_cgroup_get_unit_path_and_warn(bus, unit, &cgroup);
if (r < 0)
- return bus_log_parse_error(r);
+ return r;
if (isempty(cgroup))
return 0;
#endif // 0
typedef struct SessionStatusInfo {
- char *id;
+ const char *id;
uid_t uid;
- char *name;
+ const char *name;
struct dual_timestamp timestamp;
unsigned int vtnr;
- char *seat;
- char *tty;
- char *display;
- int remote;
- char *remote_host;
- char *remote_user;
- char *service;
+ const char *seat;
+ const char *tty;
+ const char *display;
+ bool remote;
+ const char *remote_host;
+ const char *remote_user;
+ const char *service;
pid_t leader;
- char *type;
- char *class;
- char *state;
- char *scope;
- char *desktop;
+ const char *type;
+ const char *class;
+ const char *state;
+ const char *scope;
+ const char *desktop;
} SessionStatusInfo;
typedef struct UserStatusInfo {
uid_t uid;
- int linger;
- char *name;
+ bool linger;
+ const char *name;
struct dual_timestamp timestamp;
- char *state;
+ const char *state;
char **sessions;
- char *display;
- char *slice;
+ const char *display;
+ const char *slice;
} UserStatusInfo;
typedef struct SeatStatusInfo {
- char *id;
- char *active_session;
+ const char *id;
+ const char *active_session;
char **sessions;
} SeatStatusInfo;
-static void session_status_info_clear(SessionStatusInfo *info) {
- if (info) {
- free(info->id);
- free(info->name);
- free(info->seat);
- free(info->tty);
- free(info->display);
- free(info->remote_host);
- free(info->remote_user);
- free(info->service);
- free(info->type);
- free(info->class);
- free(info->state);
- free(info->scope);
- free(info->desktop);
- zero(*info);
- }
-}
-
static void user_status_info_clear(UserStatusInfo *info) {
if (info) {
- free(info->name);
- free(info->state);
strv_free(info->sessions);
- free(info->display);
- free(info->slice);
zero(*info);
}
}
static void seat_status_info_clear(SeatStatusInfo *info) {
if (info) {
- free(info->id);
- free(info->active_session);
strv_free(info->sessions);
zero(*info);
}
if (r < 0)
return r;
- if (contents[0] == 's' || contents[0] == 'o') {
- const char *s;
- char **p = (char **) userdata;
-
- r = sd_bus_message_read_basic(m, contents[0], &s);
- if (r < 0)
- return r;
-
- r = free_and_strdup(p, s);
- if (r < 0)
- return r;
- } else {
- r = sd_bus_message_read_basic(m, contents[0], userdata);
- if (r < 0)
- return r;
- }
+ r = sd_bus_message_read_basic(m, contents[0], userdata);
+ if (r < 0)
+ return r;
r = sd_bus_message_skip(m, contents+1);
if (r < 0)
{}
};
- char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1;
- char since2[FORMAT_TIMESTAMP_MAX], *s2;
- _cleanup_(session_status_info_clear) SessionStatusInfo i = {};
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
+ char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
+ char since2[FORMAT_TIMESTAMP_MAX];
+ const char *s1, *s2;
+ SessionStatusInfo i = {};
int r;
- r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &i);
+ r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, BUS_MAP_BOOLEAN_AS_BOOL, &error, &m, &i);
if (r < 0)
- return log_error_errno(r, "Could not get properties: %m");
+ return log_error_errno(r, "Could not get properties: %s", bus_error_message(&error, r));
if (*new_line)
printf("\n");
{}
};
- char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1;
- char since2[FORMAT_TIMESTAMP_MAX], *s2;
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
+ char since1[FORMAT_TIMESTAMP_RELATIVE_MAX];
+ char since2[FORMAT_TIMESTAMP_MAX];
+ const char *s1, *s2;
_cleanup_(user_status_info_clear) UserStatusInfo i = {};
int r;
- r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &i);
+ r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, BUS_MAP_BOOLEAN_AS_BOOL, &error, &m, &i);
if (r < 0)
- return log_error_errno(r, "Could not get properties: %m");
+ return log_error_errno(r, "Could not get properties: %s", bus_error_message(&error, r));
if (*new_line)
printf("\n");
{}
};
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
_cleanup_(seat_status_info_clear) SeatStatusInfo i = {};
int r;
- r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &i);
+ r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, 0, &error, &m, &i);
if (r < 0)
- return log_error_errno(r, "Could not get properties: %m");
+ return log_error_errno(r, "Could not get properties: %s", bus_error_message(&error, r));
if (*new_line)
printf("\n");
printf("\t Devices:\n");
- show_sysfs(i.id, "\t\t ", c);
+ show_sysfs(i.id, "\t\t ", c, get_output_flags());
}
return 0;
#define property(name, fmt, ...) \
do { \
- if (arg_value) \
+ if (value) \
printf(fmt "\n", __VA_ARGS__); \
else \
printf("%s=" fmt "\n", name, __VA_ARGS__); \
- } while(0)
+ } while (0)
-static int print_property(const char *name, sd_bus_message *m, const char *contents) {
+static int print_property(const char *name, sd_bus_message *m, bool value, bool all) {
+ char type;
+ const char *contents;
int r;
assert(name);
assert(m);
- assert(contents);
- if (arg_property && !strv_find(arg_property, name))
- /* skip what we didn't read */
- return sd_bus_message_skip(m, contents);
+ r = sd_bus_message_peek_type(m, &type, &contents);
+ if (r < 0)
+ return r;
- switch (contents[0]) {
+ switch (type) {
- case SD_BUS_TYPE_STRUCT_BEGIN:
+ case SD_BUS_TYPE_STRUCT:
- if (contents[1] == SD_BUS_TYPE_STRING && STR_IN_SET(name, "Display", "Seat", "ActiveSession")) {
+ if (contents[0] == SD_BUS_TYPE_STRING && STR_IN_SET(name, "Display", "Seat", "ActiveSession")) {
const char *s;
r = sd_bus_message_read(m, "(so)", &s, NULL);
if (r < 0)
return bus_log_parse_error(r);
- if (arg_all || !isempty(s))
+ if (all || !isempty(s))
property(name, "%s", s);
- return 0;
+ return 1;
- } else if (contents[1] == SD_BUS_TYPE_UINT32 && streq(name, "User")) {
+ } else if (contents[0] == SD_BUS_TYPE_UINT32 && streq(name, "User")) {
uint32_t uid;
r = sd_bus_message_read(m, "(uo)", &uid, NULL);
}
property(name, UID_FMT, uid);
- return 0;
+ return 1;
}
-
break;
case SD_BUS_TYPE_ARRAY:
- if (contents[1] == SD_BUS_TYPE_STRUCT_BEGIN && streq(name, "Sessions")) {
+ if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && streq(name, "Sessions")) {
const char *s;
bool space = false;
if (r < 0)
return bus_log_parse_error(r);
- if (!arg_value)
+ if (!value)
printf("%s=", name);
while ((r = sd_bus_message_read(m, "(so)", &s, NULL)) > 0) {
space = true;
}
- if (space || !arg_value)
+ if (space || !value)
printf("\n");
if (r < 0)
if (r < 0)
return bus_log_parse_error(r);
- return 0;
+ return 1;
}
-
break;
}
- r = bus_print_property(name, m, arg_value, arg_all);
- if (r < 0)
- return bus_log_parse_error(r);
-
- if (r == 0) {
- r = sd_bus_message_skip(m, contents);
- if (r < 0)
- return bus_log_parse_error(r);
-
- if (arg_all)
- printf("%s=[unprintable]\n", name);
- }
-
return 0;
}
static int show_properties(sd_bus *bus, const char *path, bool *new_line) {
- _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
- _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
int r;
assert(bus);
assert(path);
assert(new_line);
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.login1",
- path,
- "org.freedesktop.DBus.Properties",
- "GetAll",
- &error,
- &reply,
- "s", "");
- if (r < 0)
- return log_error_errno(r, "Failed to get properties: %s", bus_error_message(&error, r));
-
- r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "{sv}");
- if (r < 0)
- return bus_log_parse_error(r);
-
if (*new_line)
printf("\n");
*new_line = true;
- while ((r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0) {
- const char *name, *contents;
-
- r = sd_bus_message_read(reply, "s", &name);
- if (r < 0)
- return bus_log_parse_error(r);
-
- r = sd_bus_message_peek_type(reply, NULL, &contents);
- if (r < 0)
- return bus_log_parse_error(r);
-
- r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_VARIANT, contents);
- if (r < 0)
- return bus_log_parse_error(r);
-
- r = print_property(name, reply, contents);
- if (r < 0)
- return r;
-
- r = sd_bus_message_exit_container(reply);
- if (r < 0)
- return bus_log_parse_error(r);
-
- r = sd_bus_message_exit_container(reply);
- if (r < 0)
- return bus_log_parse_error(r);
- }
- if (r < 0)
- return bus_log_parse_error(r);
-
- r = sd_bus_message_exit_container(reply);
+ r = bus_print_all_properties(bus, "org.freedesktop.login1", path, print_property, arg_property, arg_value, arg_all, NULL);
if (r < 0)
return bus_log_parse_error(r);
bool properties, new_line = false;
sd_bus *bus = userdata;
int r, i;
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_free_ char *path = NULL;
assert(bus);
assert(argv);
properties = !strstr(argv[0], "status");
- pager_open(arg_no_pager, false);
+ (void) pager_open(arg_no_pager, false);
if (argc <= 1) {
- /* If not argument is specified inspect the manager
- * itself */
+ const char *session, *p = "/org/freedesktop/login1/session/self";
+
if (properties)
+ /* If no argument is specified inspect the manager itself */
return show_properties(bus, "/org/freedesktop/login1", &new_line);
/* And in the pretty case, show data of the calling session */
- return print_session_status_info(bus, "/org/freedesktop/login1/session/self", &new_line);
+ session = getenv("XDG_SESSION_ID");
+ if (session) {
+ r = get_session_path(bus, session, &error, &path);
+ if (r < 0) {
+ log_error("Failed to get session path: %s", bus_error_message(&error, r));
+ return r;
+ }
+ p = path;
+ }
+
+ return print_session_status_info(bus, p, &new_line);
}
for (i = 1; i < argc; i++) {
- _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_free_ char *path = NULL;
-
- r = get_session_path(bus, argv[1], &error, &path);
+ r = get_session_path(bus, argv[i], &error, &path);
if (r < 0) {
log_error("Failed to get session path: %s", bus_error_message(&error, r));
return r;
properties = !strstr(argv[0], "status");
- pager_open(arg_no_pager, false);
+ (void) pager_open(arg_no_pager, false);
if (argc <= 1) {
/* If not argument is specified inspect the manager
properties = !strstr(argv[0], "status");
- pager_open(arg_no_pager, false);
+ (void) pager_open(arg_no_pager, false);
if (argc <= 1) {
/* If not argument is specified inspect the manager
assert(bus);
assert(argv);
- polkit_agent_open_if_enabled();
+ polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
if (argc < 2) {
- /* No argument? Let's convert this into the empty
- * session name, which the calls will then resolve to
- * the caller's session. */
+ /* No argument? Let's either use $XDG_SESSION_ID (if specified), or an empty
+ * session name, in which case logind will try to guess our session. */
short_argv[0] = argv[0];
- short_argv[1] = (char*) "";
+ short_argv[1] = getenv("XDG_SESSION_ID") ?: (char*) "";
short_argv[2] = NULL;
argv = short_argv;
assert(bus);
assert(argv);
- polkit_agent_open_if_enabled();
+ polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
if (!arg_kill_who)
arg_kill_who = "all";
assert(bus);
assert(argv);
- polkit_agent_open_if_enabled();
+ polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
b = streq(argv[0], "enable-linger");
if (argc < 2) {
+ /* No argument? Let's use an empty user name,
+ * then logind will use our user. */
+
short_argv[0] = argv[0];
short_argv[1] = (char*) "";
short_argv[2] = NULL;
assert(bus);
assert(argv);
- polkit_agent_open_if_enabled();
+ polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
for (i = 1; i < argc; i++) {
uid_t uid;
assert(bus);
assert(argv);
- polkit_agent_open_if_enabled();
+ polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
if (!arg_kill_who)
arg_kill_who = "all";
assert(bus);
assert(argv);
- polkit_agent_open_if_enabled();
+ polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
for (i = 2; i < argc; i++) {
assert(bus);
assert(argv);
- polkit_agent_open_if_enabled();
+ polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
r = sd_bus_call_method(
bus,
assert(bus);
assert(argv);
- polkit_agent_open_if_enabled();
+ polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
r = sd_bus_call_method(
bus,
assert(bus);
assert(argv);
- polkit_agent_open_if_enabled();
+ polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
for (i = 1; i < argc; i++) {
" -h --help Show this help\n"
" --version Show package version\n"
" --no-pager Do not pipe output into a pager\n"
-#if 1 /// elogind supports --no-wall
+#if 1 /// elogind supports --no-wall and --dry-run
" --no-wall Do not print any wall message\n"
+ " --dry-run Only print what would be done\n"
+ " -q --quiet Suppress output\n"
#endif // 1
" --no-legend Do not show the headers and footers\n"
" --no-ask-password Don't prompt for password\n"
" -s --signal=SIGNAL Which signal to send\n"
#if 0 /// UNNEEDED by elogind
" -n --lines=INTEGER Number of journal entries to show\n"
- " -o --output=STRING Change journal output mode (short, short-monotonic,\n"
- " verbose, export, json, json-pretty, json-sse, cat)\n\n"
+ " -o --output=STRING Change journal output mode (short, short-precise,\n"
+ " short-iso, short-iso-precise, short-full,\n"
+ " short-monotonic, short-unix, verbose, export,\n"
+ " json, json-pretty, json-sse, cat)\n"
#else
/// elogind can cancel shutdowns and allows to ignore inhibitors
" -c Cancel a pending shutdown or reboot\n"
" -i --ignore-inhibitors When shutting down or sleeping, ignore inhibitors\n\n"
#endif // 0
"Session Commands:\n"
+#if 0 /// elogind has "list" as a shorthand for "list-sessions"
" list-sessions List sessions\n"
+#else
+ " list[-sessions] List sessions (default command)\n"
+#endif // 0
" session-status [ID...] Show session status\n"
" show-session [ID...] Show properties of sessions or the manager\n"
" activate [ID] Activate a session\n"
" show-seat [NAME...] Show properties of seats or the manager\n"
" attach NAME DEVICE... Attach one or more devices to a seat\n"
" flush-devices Flush all device associations\n"
+#if 0 /// elogind adds some system commands to loginctl
+ " terminate-seat NAME... Terminate all sessions on one or more seats\n"
+#else
" terminate-seat NAME... Terminate all sessions on one or more seats\n\n"
-#if 1 /// elogind adds some system commands to loginctl
"System Commands:\n"
" poweroff [TIME] [WALL...] Turn off the machine\n"
" reboot [TIME] [WALL...] Reboot the machine\n"
" suspend Suspend the machine to memory\n"
" hibernate Suspend the machine to disk\n"
" hybrid-sleep Suspend the machine to memory and disk\n"
-#endif // 1
+#endif // 0
, program_invocation_short_name);
return 0;
ARG_VERSION = 0x100,
ARG_VALUE,
ARG_NO_PAGER,
-#if 1 /// elogind supports --no-wall
+#if 1 /// elogind supports --no-wall and --dry-run
ARG_NO_WALL,
+ ARG_DRY_RUN,
#endif // 1
ARG_NO_LEGEND,
ARG_KILL_WHO,
{ "value", no_argument, NULL, ARG_VALUE },
{ "full", no_argument, NULL, 'l' },
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
-#if 1 /// elogind supports --no-wall
+#if 1 /// elogind supports --no-wall, --dry-run and --quiet
{ "no-wall", no_argument, NULL, ARG_NO_WALL },
+ { "dry-run", no_argument, NULL, ARG_DRY_RUN },
+ { "quiet", no_argument, NULL, 'q' },
#endif // 1
{ "no-legend", no_argument, NULL, ARG_NO_LEGEND },
{ "kill-who", required_argument, NULL, ARG_KILL_WHO },
break;
case 'o':
+ if (streq(optarg, "help")) {
+ DUMP_STRING_TABLE(output_mode, OutputMode, _OUTPUT_MODE_MAX);
+ return 0;
+ }
+
arg_output = output_mode_from_string(optarg);
if (arg_output < 0) {
log_error("Unknown output '%s'.", optarg);
case ARG_NO_PAGER:
arg_no_pager = true;
break;
-#if 1 /// elogind supports --no-wall
+#if 1 /// elogind supports --no-wall, -dry-run and --quiet
case ARG_NO_WALL:
arg_no_wall = true;
break;
+
+ case ARG_DRY_RUN:
+ arg_dry_run = true;
+ break;
+
+ case 'q':
+ arg_quiet = true;
+ break;
+
#endif // 1
case ARG_NO_LEGEND:
break;
case 's':
- arg_signal = signal_from_string_try_harder(optarg);
+ if (streq(optarg, "help")) {
+ DUMP_STRING_TABLE(signal, int, _NSIG);
+ return 0;
+ }
+
+ arg_signal = signal_from_string(optarg);
if (arg_signal < 0) {
log_error("Failed to parse signal string %s.", optarg);
return -EINVAL;
static const Verb verbs[] = {
{ "help", VERB_ANY, VERB_ANY, 0, help },
+#if 0 /// elogind has "list" as a shorthand for "list-sessions"
{ "list-sessions", VERB_ANY, 1, VERB_DEFAULT, list_sessions },
+#else
+ { "list", VERB_ANY, 1, VERB_DEFAULT, list_sessions },
+ { "list-sessions", VERB_ANY, 1, 0, list_sessions },
+#endif // 0
{ "session-status", VERB_ANY, VERB_ANY, 0, show_session },
{ "show-session", VERB_ANY, VERB_ANY, 0, show_session },
{ "activate", VERB_ANY, 2, 0, activate },
elogind_set_program_name(argv[0]);
log_parse_environment();
log_open();
+ sigbus_install();
r = parse_argv(argc, argv);
if (r <= 0)
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();
#if 0 /// elogind does that in elogind_cleanup()
polkit_agent_close();