On Thu, Nov 01, 2018 at 09:20:10PM +0000, Jason McIntyre wrote:
> while with the current behaviour it made sense to document it that way,
> once you change it, it just sounds odd. it should really be wrapped into
> the first sentence. sth like:
> 
>       Show only those processes owned by username or UID
>       .Ar user .
Thanks, even better as this is shorter yet more precise in both places.

I'll commit it this way tomorrow unless someone objects.

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 21:25:08 -0000
@@ -177,13 +177,11 @@ seconds.
 The value may be fractional, to permit delays of less than 1 second.
 The default delay between updates is 5 seconds.
 .It Fl U Oo - Oc Ns Ar user
-Show only those processes owned by
+Show only those processes owned by username or UID
 .Ar user .
 The prefix
 .Sq -
 hides processes owned by that user.
-This option currently only accepts usernames and does not understand
-UID numbers.
 .It Fl u
 Do not take the time to map UID numbers to usernames.
 Normally,
@@ -362,7 +360,7 @@ Set the delay between screen updates to
 .Ar time
 seconds.
 .It u Oo - Oc Ns Ar user
-Show only those processes owned by
+Show only those processes owned by username or UID
 .Ar user .
 .Sq u+
 shows processes belonging to all users.
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 21:26:52 -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++;
@@ -146,7 +148,16 @@ filteruser(char buf[])
                ps.huid = (pid_t)-1;
        }
 
-       return uid_from_user(bufp, uidp);
+       if (uid_from_user(bufp, uidp) == 0)
+               return 0;
+
+       uid = strtonum(bufp, 0, UID_MAX, &errstr);
+       if (errstr == NULL && user_from_uid(uid, 1) != NULL) {
+               *uidp = uid;
+               return 0;
+       }
+
+       return -1;
 }
 
 static int

Reply via email to