From 7b1f8fb173c1dfb9454f03938c2a69ebb55e80de Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Tue, 18 Dec 2012 00:00:00 -0600 Subject: [PATCH] top: enable foreign users under 'u'/'U' task filtering This commit will allow user filtering as long as there is a valid number representing a potential user ID. It will serve, for example, chroot environments where the specific user may be unknown to a host, or vice versa. (now that we know a '.' + 2 spaces is squeezed to one) (everything's perfectly justified, but it's just luck) Reference(s): http://www.freelists.org/post/procps/top-enhancements-i-hope,1 Signed-off-by: Jim Warner --- top/top.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/top/top.c b/top/top.c index ea64770c..1786ab10 100644 --- a/top/top.c +++ b/top/top.c @@ -1174,9 +1174,16 @@ static const char *user_certify (WIN_t *q, const char *str, char typ) { Monpidsidx = 0; if (*str) { num = (uid_t)strtoul(str, &endp, 0); - if ('\0' == *endp) + if ('\0' == *endp) { pwd = getpwuid(num); - else + if (!pwd) { + /* allow foreign users, from e.g within chroot + ( thanks Dr. Werner Fink ) */ + q->usrseluid = num; + q->usrseltyp = typ; + return NULL; + } + } else pwd = getpwnam(str); if (!pwd) return N_txt(BAD_username_txt); q->usrseluid = pwd->pw_uid; -- 2.40.0