aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/top/top.c
diff options
context:
space:
mode:
authorEitan Adler <eadler@FreeBSD.org>2018-06-10 09:15:13 +0000
committerEitan Adler <eadler@FreeBSD.org>2018-06-10 09:15:13 +0000
commita01160996b89b208b1d2e62613ef9f2accc962bb (patch)
treec68ad97c71f070ebbe0f8ffb7d939ca9d3d38c7b /usr.bin/top/top.c
parent1a8f56dd3a0ba26191c764c65b489e5c02f967b3 (diff)
downloadsrc-a01160996b89b208b1d2e62613ef9f2accc962bb.tar.gz
src-a01160996b89b208b1d2e62613ef9f2accc962bb.zip
top(1): use modern interfaces for nice and related
- attempt and fail, rather than check for permission. - use macro rather than explicit "-20"
Notes
Notes: svn path=/head/; revision=334922
Diffstat (limited to 'usr.bin/top/top.c')
-rw-r--r--usr.bin/top/top.c22
1 files changed, 8 insertions, 14 deletions
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 <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 + 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 */