X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Floginctl.c;h=62d68b9072613f94842233e330668d3f5c9a713d;hb=f3f6ae7c983865ea37e8ddfbd676586e55280f1e;hp=450fbc1ebad10f576218703b6c0242cce90d0569;hpb=9f751b60fbe45dfc9fb17c5ec6452b68e9e0a89a;p=elogind.git diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 450fbc1eb..62d68b907 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -255,7 +255,6 @@ static int list_seats(int argc, char *argv[], void *userdata) { sd_bus *bus = userdata; unsigned k = 0; int r; - assert(bus); assert(argv); @@ -296,35 +295,17 @@ static int list_seats(int argc, char *argv[], void *userdata) { #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"); + r = show_cgroup_get_unit_path_and_warn(bus, unit, &cgroup); 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); - if (r < 0) - return bus_log_parse_error(r); + return r; if (isempty(cgroup)) return 0; @@ -518,14 +499,15 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li {} }; + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1; char since2[FORMAT_TIMESTAMP_MAX], *s2; _cleanup_(session_status_info_clear) 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, &error, &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"); @@ -649,14 +631,15 @@ static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line) {} }; + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; char since1[FORMAT_TIMESTAMP_RELATIVE_MAX], *s1; char since2[FORMAT_TIMESTAMP_MAX], *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, &error, &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"); @@ -725,12 +708,13 @@ static int print_seat_status_info(sd_bus *bus, const char *path, bool *new_line) {} }; + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_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, &error, &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"); @@ -944,6 +928,8 @@ static int show_session(int argc, char *argv[], void *userdata) { 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); @@ -953,20 +939,28 @@ static int show_session(int argc, char *argv[], void *userdata) { 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; @@ -1111,12 +1105,11 @@ static int activate(int argc, char *argv[], void *userdata) { polkit_agent_open_if_enabled(); 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; @@ -1192,8 +1185,11 @@ static int enable_linger(int argc, char *argv[], void *userdata) { b = streq(argv[0], "enable-linger"); if (argc < 2) { + /* 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; argc = 2; @@ -1427,15 +1423,19 @@ static int help(int argc, char *argv[], void *userdata) { " -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" - " list-sessions List sessions\n" +#if 1 /// elogind has "list" as a shorthand for "list-sessions" + " list[-sessions] List sessions (default command)\n" +#endif // 1 " session-status [ID...] Show session status\n" " show-session [ID...] Show properties of sessions or the manager\n" " activate [ID] Activate a session\n" @@ -1636,7 +1636,12 @@ static int loginctl_main(int argc, char *argv[], sd_bus *bus) { 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 },