library: expanded to provide for the UID used at login

This patch represents the newlib implementation of Jan
Rybar's merge request referenced below. It essentially
moves that code out of the ps program and into our new
library where it's available via the <pids> interface.

Reference(s):
https://gitlab.com/procps-ng/procps/merge_requests/57
https://bugzilla.redhat.com/show_bug.cgi?id=1518986

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner
2018-02-11 01:11:11 -06:00
committed by Craig Small
parent 52f0ee2c41
commit f341bd4632
4 changed files with 32 additions and 0 deletions

View File

@@ -877,6 +877,25 @@ static char *lxc_containers (const char *path) {
}
return lxc_none;
}
// Provide the user id at login (or -1 if not available)
static int login_uid (const char *path) {
char buf[PROCPATHLEN];
int fd, id, in;
id = -1;
snprintf(buf, sizeof(buf), "%s/loginuid", path);
if ((fd = open(buf, O_RDONLY, 0)) != -1) {
in = read(fd, buf, sizeof(buf) - 1);
close(fd);
if (in > 0) {
buf[in] = '\0';
id = atoi(buf);
}
}
return id;
}
///////////////////////////////////////////////////////////////////////
@@ -998,6 +1017,9 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
if (flags & PROC_FILL_LXC) // value the lxc name
p->lxcname = lxc_containers(path);
if (flags & PROC_FILL_LUID) // value the login user id
p->luid = login_uid(path);
if (rc == 0) return p;
errno = ENOMEM;
next_proc:
@@ -1132,6 +1154,9 @@ static proc_t* simple_readtask(PROCTAB *restrict const PT, const proc_t *restric
if (flags & PROC_FILL_LXC)
t->lxcname = lxc_containers(path);
if (flags & PROC_FILL_LUID)
t->luid = login_uid(path);
if (rc == 0) return t;
errno = ENOMEM;
next_task: