This makes `top -U 0' and "u-1000" work. Overview:
"kn" ok "10kn" ok if "10kn" exists else error "-kn" ok "-10kn" ok if "10kn" exists else error "1000" ok "--1000" error, negative UID and "-1000" not valid "-1000" ok "--10kn" error, "-10kn" not valid I wanted to drop the restriction from the manual page first, but this would actually remove information so shortly state what's accepted. Feedback? OK? Index: top.1 =================================================================== RCS file: /cvs/src/usr.bin/top/top.1,v retrieving revision 1.69 diff -u -p -r1.69 top.1 --- top.1 25 Jul 2018 17:24:14 -0000 1.69 +++ top.1 1 Nov 2018 18:28:29 -0000 @@ -182,8 +182,7 @@ Show only those processes owned by The prefix .Sq - hides processes owned by that user. -This option currently only accepts usernames and does not understand -UID numbers. +This option accepts usernames and UID numbers. .It Fl u Do not take the time to map UID numbers to usernames. Normally, Index: top.c =================================================================== RCS file: /cvs/src/usr.bin/top/top.c,v retrieving revision 1.95 diff -u -p -r1.95 top.c --- top.c 1 Nov 2018 18:04:13 -0000 1.95 +++ top.c 1 Nov 2018 18:28:29 -0000 @@ -134,8 +134,10 @@ usage(void) static int filteruser(char buf[]) { + const char *errstr; char *bufp = buf; uid_t *uidp; + uid_t uid; if (bufp[0] == '-') { bufp++; @@ -144,6 +146,12 @@ filteruser(char buf[]) } else { uidp = &ps.uid; ps.huid = (pid_t)-1; + } + + uid = strtonum(bufp, 0, UID_MAX, &errstr); + if (errstr == NULL && user_from_uid(uid, 1) != NULL) { + *uidp = uid; + return 0; } return uid_from_user(bufp, uidp);