]> granicus.if.org Git - procps-ng/commitdiff
ps: possibility to display systemd user unit for a process
authorLukas Nykryn <lnykryn@redhat.com>
Mon, 22 Apr 2013 10:56:02 +0000 (12:56 +0200)
committerLukas Nykryn <lnykryn@redhat.com>
Wed, 24 Apr 2013 07:24:44 +0000 (09:24 +0200)
Library systemd-login offers possibility to display
name of systemd user unit for specific pid. Note that not all
processes are part of a user unit.

This patch adds output option "sd_uunit" which will
show name of user unit or "-", when process does not belong
to any user unit. This is similar to "sd_unit" but applies
to user units instead of system units.

To maintain compatibility with non-systemd systems,
procps must be configured with --with-systemd option
to enable this option.

ps/output.c
ps/ps.1

index 771d6ffcc9a6d2f240a33ae31ccf07443b60bcfe..4ccc6c3beedd753fb0ffe0222d63c63d982c0f3f 100644 (file)
@@ -1240,6 +1240,24 @@ fail:
   outbuf[1] = '\0';
   return 1;
 }
+
+static int pr_sd_uunit(char *restrict const outbuf, const proc_t *restrict const pp){
+  int r;
+  size_t len;
+  char *unit;
+
+  r = sd_pid_get_user_unit(pp->tgid, &unit);
+  if(r<0) goto fail;
+  len = snprintf(outbuf, COLWID, "%s", unit);
+  free(unit);
+  return len;
+
+fail:
+  outbuf[0] = '-';
+  outbuf[1] = '\0';
+  return 1;
+}
+
 #endif
 /****************** FLASK & seLinux security stuff **********************/
 // move the bulk of this to libproc sometime
@@ -1572,6 +1590,7 @@ static const format_struct format_array[] = {
 {"sd_ouid",   "OWNER",   pr_sd_ouid,  sr_nop,     5,   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},
 #endif
 {"sess",      "SESS",    pr_sess,     sr_session, 5,   0,    XXX, PO|PIDMAX|RIGHT},
 {"session",   "SESS",    pr_sess,     sr_session, 5,   0,    LNX, PO|PIDMAX|RIGHT},
diff --git a/ps/ps.1 b/ps/ps.1
index 30718a15dc8dd537cf1db00a68ad3cd219946e37..df2400fa15953009d764705a04a5cfccb807c4be 100644 (file)
--- a/ps/ps.1
+++ b/ps/ps.1
@@ -1505,6 +1505,10 @@ sd_unit  UNIT    T{
 displays systemd unit which a process belongs to.
 T}
 
+sd_uunit       UUNIT   T{
+displays systemd user unit which a process belongs to.
+T}
+
 sess   SESS    T{
 session ID or, equivalently, the process ID of the session leader.  (alias
 .BR session , \ sid ).