From owner-svn-src-head@FreeBSD.ORG Tue Dec 27 20:03:58 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7EE171065673; Tue, 27 Dec 2011 20:03:58 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6379E8FC0A; Tue, 27 Dec 2011 20:03:58 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id pBRK3wv9066983; Tue, 27 Dec 2011 20:03:58 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id pBRK3wqS066981; Tue, 27 Dec 2011 20:03:58 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <201112272003.pBRK3wqS066981@svn.freebsd.org> From: Xin LI Date: Tue, 27 Dec 2011 20:03:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r228917 - head/usr.sbin/rtprio X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 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: Tue, 27 Dec 2011 20:03:58 -0000 Author: delphij Date: Tue Dec 27 20:03:57 2011 New Revision: 228917 URL: http://svn.freebsd.org/changeset/base/228917 Log: - Fail when the utility is not invoked as rtprio nor idprio. - use warnx() to tell the user whether a process is running in normal, idle or realtime priority. with the old code it would have been possible for another process to send data to stdout between printf("%s: ", p); and printf("* priority\n"); and thus break the formatting. - 'rtprio 10 -0' triggeres non-intuitive behavior. It would first set the priority of itself to 10 *and* would then try to execute '-0'. Of course, setting the priority of [id|rt]prio itself doesn't make a lot of sense, but it is intuitive compared to the previous behavior. - 'rtprio -t --1' will actually pass over the '-1' to rtprio(). Now invoking rtprio like this will catch the wrong usage before passing over the invalid argument to rtprio(). - Garrett Cooper suggested to add further diagnostics where the failure occures, if execvp fails. PR: bin/154042 Submitted by: arundel MFC after: 1 month Modified: head/usr.sbin/rtprio/rtprio.c Modified: head/usr.sbin/rtprio/rtprio.c ============================================================================== --- head/usr.sbin/rtprio/rtprio.c Tue Dec 27 15:59:51 2011 (r228916) +++ head/usr.sbin/rtprio/rtprio.c Tue Dec 27 20:03:57 2011 (r228917) @@ -53,20 +53,17 @@ int main(int argc, char *argv[]) { struct rtprio rtp; - char *p; - pid_t proc; + const char *progname; + pid_t proc = 0; - /* find basename */ - if ((p = rindex(argv[0], '/')) == NULL) - p = argv[0]; - else - ++p; - proc = 0; + progname = getprogname(); - if (!strcmp(p, "rtprio")) + if (strcmp(progname, "rtprio") == 0) rtp.type = RTP_PRIO_REALTIME; - else if (!strcmp(p, "idprio")) + else if (strcmp(progname, "idprio") == 0) rtp.type = RTP_PRIO_IDLE; + else + errx(1, "invalid progname"); switch (argc) { case 2: @@ -76,20 +73,19 @@ main(int argc, char *argv[]) case 1: if (rtprio(RTP_LOOKUP, proc, &rtp) != 0) err(1, "RTP_LOOKUP"); - printf("%s: ", p); switch (rtp.type) { case RTP_PRIO_REALTIME: case RTP_PRIO_FIFO: - printf("realtime priority %d\n", rtp.prio); + warnx("realtime priority %d", rtp.prio); break; case RTP_PRIO_NORMAL: - printf("normal priority\n"); + warnx("normal priority"); break; case RTP_PRIO_IDLE: - printf("idle priority %d\n", rtp.prio); + warnx("idle priority %d", rtp.prio); break; default: - printf("invalid priority type %d\n", rtp.type); + errx(1, "invalid priority type %d", rtp.type); break; } exit(0); @@ -110,18 +106,18 @@ main(int argc, char *argv[]) break; } - if (argv[2][0] == '-') - proc = parseint(argv[2] + 1, "pid"); - if (rtprio(RTP_SET, proc, &rtp) != 0) - err(1, "RTP_SET"); - - if (proc == 0) { + if (argv[2][0] == '-') { + proc = parseint(argv[2], "pid"); + proc = abs(proc); + if (rtprio(RTP_SET, proc, &rtp) != 0) + err(1, "RTP_SET"); + } else { execvp(argv[2], &argv[2]); - err(1, "%s", argv[2]); + err(1, "execvp: %s", argv[2]); } exit(0); } - exit(1); + /* NOTREACHED */ } static int