From owner-svn-src-stable-9@FreeBSD.ORG Fri May 18 00:40:50 2012 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 54206106566B; Fri, 18 May 2012 00:40:50 +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 3E2408FC08; Fri, 18 May 2012 00:40:50 +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 q4I0eot1025278; Fri, 18 May 2012 00:40:50 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q4I0eorP025276; Fri, 18 May 2012 00:40:50 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <201205180040.q4I0eorP025276@svn.freebsd.org> From: Xin LI Date: Fri, 18 May 2012 00:40:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r235577 - stable/9/usr.sbin/rtprio X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 May 2012 00:40:50 -0000 Author: delphij Date: Fri May 18 00:40:49 2012 New Revision: 235577 URL: http://svn.freebsd.org/changeset/base/235577 Log: MFC r228917: - 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 r235293: Fix the case where the utility is being used to run a command directly, this is a regression introduced with r228917. PR: bin/154042 Submitted by: Bugs Beastie Modified: stable/9/usr.sbin/rtprio/rtprio.c Directory Properties: stable/9/usr.sbin/rtprio/ (props changed) Modified: stable/9/usr.sbin/rtprio/rtprio.c ============================================================================== --- stable/9/usr.sbin/rtprio/rtprio.c Fri May 18 00:32:29 2012 (r235576) +++ stable/9/usr.sbin/rtprio/rtprio.c Fri May 18 00:40:49 2012 (r235577) @@ -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,21 @@ main(int argc, char *argv[]) break; } - if (argv[2][0] == '-') - proc = parseint(argv[2] + 1, "pid"); + if (argv[2][0] == '-') { + proc = parseint(argv[2], "pid"); + proc = abs(proc); + } + if (rtprio(RTP_SET, proc, &rtp) != 0) err(1, "RTP_SET"); if (proc == 0) { execvp(argv[2], &argv[2]); - err(1, "%s", argv[2]); + err(1, "execvp: %s", argv[2]); } exit(0); } - exit(1); + /* NOTREACHED */ } static int