From owner-svn-src-head@freebsd.org Sun Jun 10 09:15:14 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 725E7100A238; Sun, 10 Jun 2018 09:15:14 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 28B8E77837; Sun, 10 Jun 2018 09:15:14 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E66A72A51; Sun, 10 Jun 2018 09:15:13 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5A9FD8V092329; Sun, 10 Jun 2018 09:15:13 GMT (envelope-from eadler@FreeBSD.org) Received: (from eadler@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5A9FD6q092326; Sun, 10 Jun 2018 09:15:13 GMT (envelope-from eadler@FreeBSD.org) Message-Id: <201806100915.w5A9FD6q092326@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eadler set sender to eadler@FreeBSD.org using -f From: Eitan Adler Date: Sun, 10 Jun 2018 09:15:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334922 - head/usr.bin/top X-SVN-Group: head X-SVN-Commit-Author: eadler X-SVN-Commit-Paths: head/usr.bin/top X-SVN-Commit-Revision: 334922 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Jun 2018 09:15:14 -0000 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 #include #include +#include #include #include -#include #include #include @@ -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 */