7e6f622
diff -up ./ps/output.c.ori ./ps/output.c
7e6f622
--- ./ps/output.c.ori	2016-07-09 23:49:25.825306872 +0200
7e6f622
+++ ./ps/output.c	2018-02-26 15:09:38.291043349 +0100
7e6f622
@@ -1201,6 +1201,34 @@ static int pr_sgi_p(char *restrict const
7e6f622
   return snprintf(outbuf, COLWID, "*");
7e6f622
 }
7e6f622
 
7e6f622
+/* LoginID implementation */
7e6f622
+static int pr_luid(char *restrict const outbuf, const proc_t *restrict const pp){
7e6f622
+    char filename[48];
7e6f622
+    ssize_t num_read;
7e6f622
+    int fd;
7e6f622
+    u_int32_t luid;
7e6f622
+
7e6f622
+    snprintf(filename, sizeof filename, "/proc/%d/loginuid", pp->tgid);
7e6f622
+
7e6f622
+    if ((fd = open(filename, O_RDONLY, 0)) != -1) {
7e6f622
+        num_read = read(fd, outbuf, OUTBUF_SIZE - 1);
7e6f622
+        close(fd);
7e6f622
+        if (num_read > 0) {
7e6f622
+            outbuf[num_read] = '\0';
7e6f622
+
7e6f622
+            // processes born before audit have no LoginID set
7e6f622
+            luid = (u_int32_t) atoi(outbuf);
7e6f622
+            if (luid != -1)
7e6f622
+                return num_read;
7e6f622
+        }
7e6f622
+    }
7e6f622
+    outbuf[0] = '-';
7e6f622
+    outbuf[1] = '\0';
7e6f622
+    num_read = 1;
7e6f622
+    return num_read;
7e6f622
+}
7e6f622
+
7e6f622
+
7e6f622
 /************************* Systemd stuff ********************************/
7e6f622
 static int pr_sd_unit(char *restrict const outbuf, const proc_t *restrict const pp){
7e6f622
   return snprintf(outbuf, COLWID, "%s", pp->sd_unit);
7e6f622
@@ -1513,7 +1541,7 @@ static const format_struct format_array[
7e6f622
 {"longtname", "TTY",     pr_tty8,     sr_tty,     8,   0,    DEC, PO|LEFT},
7e6f622
 {"lsession",  "SESSION", pr_sd_session, sr_nop,  11,  SD,    LNX, ET|LEFT},
7e6f622
 {"lstart",    "STARTED", pr_lstart,   sr_nop,    24,   0,    XXX, ET|RIGHT},
7e6f622
-{"luid",      "LUID",    pr_nop,      sr_nop,     5,   0,    LNX, ET|RIGHT}, /* login ID */
7e6f622
+{"luid",      "LUID",    pr_luid,     sr_nop,     5,   0,    LNX, ET|RIGHT}, /* login ID */
7e6f622
 {"luser",     "LUSER",   pr_nop,      sr_nop,     8, USR,    LNX, ET|USER}, /* login USER */
7e6f622
 {"lwp",       "LWP",     pr_tasks,    sr_tasks,   5,   0,    SUN, TO|PIDMAX|RIGHT},
7e6f622
 {"lxc",       "LXC",     pr_lxcname,  sr_lxcname, 8, LXC,    LNX, ET|LEFT},
7e6f622
diff -up ./ps/ps.1.ori ./ps/ps.1
7e6f622
--- ./ps/ps.1.ori	2016-05-07 13:15:32.014390172 +0200
7e6f622
+++ ./ps/ps.1	2018-02-26 15:09:38.292043345 +0100
7e6f622
@@ -1322,6 +1322,10 @@ displays the login session identifier of
7e6f622
 if systemd support has been included.
7e6f622
 T}
7e6f622
 
7e6f622
+luid	LUID	T{
7e6f622
+displays Login ID associated with a process.
7e6f622
+T}
7e6f622
+
7e6f622
 lwp	LWP	T{
7e6f622
 light weight process (thread) ID of the dispatchable entity (alias
7e6f622
 .BR spid , \ tid ).