]> granicus.if.org Git - procps-ng/commitdiff
ps: LUID format option impelemented
authorJan Rybar <jrybar@redhat.com>
Fri, 9 Feb 2018 17:17:36 +0000 (18:17 +0100)
committerCraig Small <csmall@enc.com.au>
Mon, 19 Feb 2018 09:41:40 +0000 (20:41 +1100)
ps/output.c
ps/ps.1

index 573666c6664f3bc3e16689a41d7739b3d0fb4a76..218393890842fc98c21bcb808fb96244430eff40 100644 (file)
@@ -1213,6 +1213,34 @@ static int pr_sgi_p(char *restrict const outbuf, const proc_t *restrict const pp
   return snprintf(outbuf, COLWID, "*");
 }
 
+/* LoginID implementation */
+static int pr_luid(char *restrict const outbuf, const proc_t *restrict const pp){
+    char filename[48];
+    ssize_t num_read;
+    int fd;
+    u_int32_t luid;
+
+    snprintf(filename, sizeof filename, "/proc/%d/loginuid", pp->tgid);
+
+    if ((fd = open(filename, O_RDONLY, 0)) != -1) {
+        num_read = read(fd, outbuf, OUTBUF_SIZE - 1);
+        close(fd);
+        if (num_read > 0) {
+            outbuf[num_read] = '\0';
+
+            // processes born before audit have no LoginID set
+            luid = (u_int32_t) atoi(outbuf);
+            if (luid != -1)
+                return num_read;
+        }
+    }
+    outbuf[0] = '-';
+    outbuf[1] = '\0';
+    num_read = 1;
+    return num_read;
+}
+
+
 /************************* Systemd stuff ********************************/
 static int pr_sd_unit(char *restrict const outbuf, const proc_t *restrict const pp){
   return snprintf(outbuf, COLWID, "%s", pp->sd_unit);
@@ -1526,7 +1554,7 @@ static const format_struct format_array[] = {
 {"longtname", "TTY",     pr_tty8,     sr_tty,     8,   0,    DEC, PO|LEFT},
 {"lsession",  "SESSION", pr_sd_session, sr_nop,  11,  SD,    LNX, ET|LEFT},
 {"lstart",    "STARTED", pr_lstart,   sr_nop,    24,   0,    XXX, ET|RIGHT},
-{"luid",      "LUID",    pr_nop,      sr_nop,     5,   0,    LNX, ET|RIGHT}, /* login ID */
+{"luid",      "LUID",    pr_luid,     sr_nop,     5,   0,    LNX, ET|RIGHT}, /* login ID */
 {"luser",     "LUSER",   pr_nop,      sr_nop,     8, USR,    LNX, ET|USER}, /* login USER */
 {"lwp",       "LWP",     pr_tasks,    sr_tasks,   5,   0,    SUN, TO|PIDMAX|RIGHT},
 {"lxc",       "LXC",     pr_lxcname,  sr_lxcname, 8, LXC,    LNX, ET|LEFT},
diff --git a/ps/ps.1 b/ps/ps.1
index c16d00db4c5d76ded3858673101e685065d7d9eb..e239f942979636a4193513446d628f7e4c0dfe76 100644 (file)
--- a/ps/ps.1
+++ b/ps/ps.1
@@ -1329,6 +1329,10 @@ displays the login session identifier of a process,
 if systemd support has been included.
 T}
 
+luid   LUID    T{
+displays Login ID associated with a process.
+T}
+
 lwp    LWP     T{
 light weight process (thread) ID of the dispatchable entity (alias
 .BR spid , \ tid ).