From 7b50c2e9184a64f4b65a3197db24d271b3052b55 Mon Sep 17 00:00:00 2001 From: Lukas Nykryn Date: Mon, 22 Apr 2013 13:16:33 +0200 Subject: [PATCH] ps: possibility to display seat for a process Library systemd-login offers possibility to display name of seat for a session on multi-seat systems. This patch adds output option "sd_seat" which will show name of seat or "-", when name of seat can not be determined, but "seat0" should always exist. To maintain compatibility with non-systemd systems, procps must be configured with --with-systemd option to enable this option. --- ps/output.c | 21 +++++++++++++++++++++ ps/ps.1 | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/ps/output.c b/ps/output.c index 4ccc6c3b..6b5f19c0 100644 --- a/ps/output.c +++ b/ps/output.c @@ -1258,6 +1258,26 @@ fail: return 1; } +static int pr_sd_seat(char *restrict const outbuf, const proc_t *restrict const pp){ + int r; + size_t len; + char *session; + char *seat; + r = sd_pid_get_session(pp->tgid, &session); + if(r<0) goto fail; + r = sd_session_get_seat(session, &seat); + free(session); + if(r<0) goto fail; + len = snprintf(outbuf, COLWID, "%s", seat); + free(seat); + return len; + +fail: + outbuf[0] = '-'; + outbuf[1] = '\0'; + return 1; +} + #endif /****************** FLASK & seLinux security stuff **********************/ // move the bulk of this to libproc sometime @@ -1588,6 +1608,7 @@ static const format_struct format_array[] = { #ifdef WITH_SYSTEMD {"sd_machine","MACHINE", pr_sd_machine, sr_nop, 31, 0, LNX, ET|LEFT}, {"sd_ouid", "OWNER", pr_sd_ouid, sr_nop, 5, 0, LNX, ET|LEFT}, +{"sd_seat", "SEAT", pr_sd_seat, sr_nop, 11, 0, LNX, ET|LEFT}, {"sd_session","SESSION", pr_sd_session, sr_nop, 11, 0, LNX, ET|LEFT}, {"sd_unit", "UNIT", pr_sd_unit, sr_nop, 31, 0, LNX, ET|LEFT}, {"sd_uunit", "UUNIT", pr_sd_uunit, sr_nop, 31, 0, LNX, ET|LEFT}, diff --git a/ps/ps.1 b/ps/ps.1 index df2400fa..af249c2c 100644 --- a/ps/ps.1 +++ b/ps/ps.1 @@ -1497,6 +1497,10 @@ sd_ouid OWNER T{ displays the Unix user identifier of the owner of the session of a process. T} +sd_seat SEAT T{ +displays login session identifier of a process. +T} + sd_session SESSION T{ displays login session identifier of a process. T}