ps: LUID (LoginID) format option available

This commit is contained in:
Jan Rybar 2018-02-27 16:09:56 +01:00
parent 0568cb60bf
commit 7e6f622b67
2 changed files with 69 additions and 1 deletions

View File

@ -0,0 +1,61 @@
diff -up ./ps/output.c.ori ./ps/output.c
--- ./ps/output.c.ori 2016-07-09 23:49:25.825306872 +0200
+++ ./ps/output.c 2018-02-26 15:09:38.291043349 +0100
@@ -1201,6 +1201,34 @@ static int pr_sgi_p(char *restrict const
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);
@@ -1513,7 +1541,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 -up ./ps/ps.1.ori ./ps/ps.1
--- ./ps/ps.1.ori 2016-05-07 13:15:32.014390172 +0200
+++ ./ps/ps.1 2018-02-26 15:09:38.292043345 +0100
@@ -1322,6 +1322,10 @@ displays the login session identifier of
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 ).

View File

@ -4,7 +4,7 @@
Summary: System and process monitoring utilities
Name: procps-ng
Version: 3.3.12
Release: 1%{?dist}
Release: 2%{?dist}
License: GPL+ and GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+
Group: Applications/System
URL: https://sourceforge.net/projects/procps-ng/
@ -16,6 +16,8 @@ Source1: README.md
# wget https://gitlab.com/procps-ng/procps/raw/e0784ddaed30d095bb1d9a8ad6b5a23d10a212c4/top/README.top
Source2: README.top
Patch0: procps-ng-3.3.12-ps-luid-format-option.patch
BuildRequires: ncurses-devel
BuildRequires: libtool
BuildRequires: autoconf
@ -89,6 +91,8 @@ Internationalization pack for procps-ng
cp -p %{SOURCE1} .
cp -p %{SOURCE2} top/
%patch0 -p1
%build
# The following stuff is needed for git archives only
@ -159,6 +163,9 @@ ln -s %{_bindir}/pidof %{buildroot}%{_sbindir}/pidof
%files i18n -f %{name}.lang
%changelog
* Mon Feb 26 2018 Jan Rybar <jrybar@redhat.com> - 3.3.12-2
- ps: LUID (LoginID) format option available
* Wed Feb 21 2018 Michael Cronenworth <mike@cchtml.com> - 3.3.12-1
- Upgrading to 3.3.12