diff --git a/usr.bin/top/commands.c b/usr.bin/top/commands.c index 9dcd8117e9f9..716648f6af6b 100644 --- a/usr.bin/top/commands.c +++ b/usr.bin/top/commands.c @@ -379,14 +379,10 @@ kill_procs(char *str) char *nptr; int signum = SIGTERM; /* default */ int procnum; - int uid; /* reset error array */ ERR_RESET; - /* remember our uid */ - uid = getuid(); - /* skip over leading white space */ while (isspace(*str)) str++; @@ -429,13 +425,8 @@ kill_procs(char *str) } else { - /* check process owner if we're not root */ - if (uid && (uid != proc_owner(procnum))) - { - ERROR(str, EACCES); - } /* go in for the kill */ - else if (kill(procnum, signum) == -1) + if (kill(procnum, signum) == -1) { /* chalk up an error */ ERROR(str, errno); @@ -458,10 +449,8 @@ renice_procs(char *str) char negate; int prio; int procnum; - int uid; ERR_RESET; - uid = getuid(); /* allow for negative priority values */ if ((negate = (*str == '-')) != 0) @@ -499,12 +488,7 @@ renice_procs(char *str) ERROR(str, 0); } - /* check process owner if we're not root */ - else if (uid && (uid != proc_owner(procnum))) - { - ERROR(str, EACCES); - } - else if (setpriority(PRIO_PROCESS, procnum, prio) == -1) + if (setpriority(PRIO_PROCESS, procnum, prio) == -1) { ERROR(str, errno); } diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index 087d022058a9..b7edfb83d1ed 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -16,9 +16,9 @@ #include #include #include +#include #include #include -#include #include #include @@ -439,19 +439,13 @@ _Static_assert(sizeof(command_chars) == CMD_toggletid + 2, "command chars size") break; case 'q': /* be quick about it */ - /* only allow this if user is really root */ - if (getuid() == 0) - { - /* be very un-nice! */ - nice(-20); - } - else - { - fprintf(stderr, - "%s: warning: `-q' option can only be used by root\n", - myname); - warnings++; - } + errno = 0; + i = setpriority(PRIO_PROCESS, 0, PRIO_MIN); + if (i == -1 && errno != 0) { + fprintf(stderr, + "%s: warning: `-q' option failed (%m)\n", myname); + warnings++; + } break; case 'm': /* select display mode */