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