From: Jim Warner <james.warner@comcast.net> Date: Tue, 18 Dec 2012 06:00:00 +0000 (-0600) Subject: top: enable foreign users under 'u'/'U' task filtering X-Git-Tag: v3.3.6~17 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b1f8fb173c1dfb9454f03938c2a69ebb55e80de;p=procps-ng 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 <james.warner@comcast.net> --- 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 <werner@suse.de> ) */ + 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;