summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-10-17 11:36:25 +0200
committerGitHub <noreply@github.com>2016-10-17 11:36:25 +0200
commitf213900b5a80cc7a269f3da7e4f68b703c2edf32 (patch)
tree3576cbab6bab8053d60f0f1f096d3e09d5663e19
parentba25d39e449347952522162c3fa110b04308e28c (diff)
parent5611ddebe4dd800410f0c413ee034735e1d9993c (diff)
Merge pull request #4387 from keszybz/loginctl-tty
loginctl: print TTY field in the session listing
-rw-r--r--src/login/loginctl.c90
1 files changed, 67 insertions, 23 deletions
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 0fc33cf541..4c618ed19e 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -83,6 +83,34 @@ static OutputFlags get_output_flags(void) {
colors_enabled() * OUTPUT_COLOR;
}
+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;
+ int r;
+ char *ans;
+
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ "GetSession",
+ error, &reply,
+ "s", session_id);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_read(reply, "o", &ans);
+ if (r < 0)
+ return r;
+
+ ans = strdup(ans);
+ if (!ans)
+ return -ENOMEM;
+
+ *path = ans;
+ 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;
@@ -115,10 +143,38 @@ static int list_sessions(int argc, char *argv[], void *userdata) {
return bus_log_parse_error(r);
if (arg_legend)
- printf("%10s %10s %-16s %-16s\n", "SESSION", "UID", "USER", "SEAT");
+ printf("%10s %10s %-16s %-16s %-16s\n", "SESSION", "UID", "USER", "SEAT", "TTY");
while ((r = sd_bus_message_read(reply, "(susso)", &id, &uid, &user, &seat, &object)) > 0) {
- printf("%10s %10u %-16s %-16s\n", id, (unsigned) uid, user, seat);
+ _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 = get_session_path(bus, id, &error2, &path);
+ if (r < 0)
+ log_warning("Failed to get session path: %s", bus_error_message(&error, r));
+ else {
+ r = sd_bus_get_property(
+ bus,
+ "org.freedesktop.login1",
+ path,
+ "org.freedesktop.login1.Session",
+ "TTY",
+ &error2,
+ &reply2,
+ "s");
+ 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);
+ }
+ }
+
+ printf("%10s %10"PRIu32" %-16s %-16s %-16s\n", id, uid, user, seat, strna(tty));
k++;
}
if (r < 0)
@@ -165,7 +221,7 @@ static int list_users(int argc, char *argv[], void *userdata) {
printf("%10s %-16s\n", "UID", "USER");
while ((r = sd_bus_message_read(reply, "(uso)", &uid, &user, &object)) > 0) {
- printf("%10u %-16s\n", (unsigned) uid, user);
+ printf("%10"PRIu32" %-16s\n", uid, user);
k++;
}
if (r < 0)
@@ -462,9 +518,9 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
printf("%s - ", strna(i.id));
if (i.name)
- printf("%s (%u)\n", i.name, (unsigned) i.uid);
+ printf("%s (%"PRIu32")\n", i.name, i.uid);
else
- printf("%u\n", (unsigned) i.uid);
+ printf("%"PRIu32"\n", i.uid);
s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
s2 = format_timestamp(since2, sizeof(since2), i.timestamp.realtime);
@@ -477,7 +533,7 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
if (i.leader > 0) {
_cleanup_free_ char *t = NULL;
- printf("\t Leader: %u", (unsigned) i.leader);
+ printf("\t Leader: %"PRIu32, i.leader);
get_process_comm(i.leader, &t);
if (t)
@@ -589,9 +645,9 @@ static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line)
*new_line = true;
if (i.name)
- printf("%s (%u)\n", i.name, (unsigned) i.uid);
+ printf("%s (%"PRIu32")\n", i.name, i.uid);
else
- printf("%u\n", (unsigned) i.uid);
+ printf("%"PRIu32"\n", i.uid);
s1 = format_timestamp_relative(since1, sizeof(since1), i.timestamp.realtime);
s2 = format_timestamp(since2, sizeof(since2), i.timestamp.realtime);
@@ -887,26 +943,14 @@ static int show_session(int argc, char *argv[], void *userdata) {
for (i = 1; i < argc; i++) {
_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 *path = NULL;
+ _cleanup_free_ char *path = NULL;
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "GetSession",
- &error, &reply,
- "s", argv[i]);
+ r = get_session_path(bus, argv[1], &error, &path);
if (r < 0) {
- log_error("Failed to get session: %s", bus_error_message(&error, r));
+ log_error("Failed to get session path: %s", bus_error_message(&error, r));
return r;
}
- r = sd_bus_message_read(reply, "o", &path);
- if (r < 0)
- return bus_log_parse_error(r);
-
if (properties)
r = show_properties(bus, path, &new_line);
else