svn commit: r334922 - head/usr.bin/top
Eitan Adler
eadler at FreeBSD.org
Sun Jun 10 09:15:14 UTC 2018
Author: eadler
Date: Sun Jun 10 09:15:13 2018
New Revision: 334922
URL: https://svnweb.freebsd.org/changeset/base/334922
Log:
top(1): use modern interfaces for nice and related
- attempt and fail, rather than check for permission.
- use macro rather than explicit "-20"
Modified:
head/usr.bin/top/commands.c
head/usr.bin/top/top.c
Modified: head/usr.bin/top/commands.c
==============================================================================
--- head/usr.bin/top/commands.c Sun Jun 10 09:04:56 2018 (r334921)
+++ head/usr.bin/top/commands.c Sun Jun 10 09:15:13 2018 (r334922)
@@ -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);
}
Modified: head/usr.bin/top/top.c
==============================================================================
--- head/usr.bin/top/top.c Sun Jun 10 09:04:56 2018 (r334921)
+++ head/usr.bin/top/top.c Sun Jun 10 09:15:13 2018 (r334922)
@@ -16,9 +16,9 @@
#include <sys/time.h>
#include <sys/cdefs.h>
#include <sys/limits.h>
+#include <sys/resource.h>
#include <sys/select.h>
#include <sys/signal.h>
-#include <time.h>
#include <errno.h>
#include <getopt.h>
@@ -439,19 +439,13 @@ _Static_assert(sizeof(command_chars) == CMD_toggletid
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 */
More information about the svn-src-all
mailing list