From owner-freebsd-bugs@FreeBSD.ORG Sat Jan 15 22:20:10 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 020EF1065672 for ; Sat, 15 Jan 2011 22:20:10 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id B94628FC15 for ; Sat, 15 Jan 2011 22:20:09 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p0FMK9kF014526 for ; Sat, 15 Jan 2011 22:20:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p0FMK9uN014525; Sat, 15 Jan 2011 22:20:09 GMT (envelope-from gnats) Resent-Date: Sat, 15 Jan 2011 22:20:09 GMT Resent-Message-Id: <201101152220.p0FMK9uN014525@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Alexander Best Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 979E010656A3 for ; Sat, 15 Jan 2011 22:10:54 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (unknown [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 875828FC23 for ; Sat, 15 Jan 2011 22:10:54 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p0FMAsDL082669 for ; Sat, 15 Jan 2011 22:10:54 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id p0FMAsnw082668; Sat, 15 Jan 2011 22:10:54 GMT (envelope-from nobody) Message-Id: <201101152210.p0FMAsnw082668@red.freebsd.org> Date: Sat, 15 Jan 2011 22:10:54 GMT From: Alexander Best To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/154042: [patch] fix several rtprio(1) issues X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 15 Jan 2011 22:20:10 -0000 >Number: 154042 >Category: bin >Synopsis: [patch] fix several rtprio(1) issues >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Jan 15 22:20:09 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Alexander Best >Release: 9.0-CURRENT >Organization: >Environment: FreeBSD otaku 9.0-CURRENT FreeBSD 9.0-CURRENT #0 r217444: Sat Jan 15 18:48:59 CET 2011 arundel@otaku:/usr/obj/usr/subversion-src/sys/ARUNDEL amd64 >Description: this patch should fix the following issues: 1) fail when the utility wasn't invoked as rtprio or idprio. 2) 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. 3) '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. 4) '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(). 5) Garrett Cooper suggested to add further diagnostics where the failure occures, if execvp fails. cheers. alex >How-To-Repeat: run 'rtprio 10 -0' or 'rtprio -t --1' on HEAD (>= r216955) to witness a few issues. >Fix: Patch attached with submission follows: diff --git a/usr.sbin/rtprio/rtprio.c b/usr.sbin/rtprio/rtprio.c index 38dade8..f794ec9 100644 --- a/usr.sbin/rtprio/rtprio.c +++ b/usr.sbin/rtprio/rtprio.c @@ -67,6 +67,8 @@ main(int argc, char *argv[]) rtp.type = RTP_PRIO_REALTIME; else if (!strcmp(p, "idprio")) rtp.type = RTP_PRIO_IDLE; + else + errx(1, "invalid basename"); switch (argc) { case 2: @@ -76,20 +78,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 +111,17 @@ 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); } static int >Release-Note: >Audit-Trail: >Unformatted: