From nobody@FreeBSD.org  Sat Jan 15 22:10:54 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 979E010656A3
	for <freebsd-gnats-submit@FreeBSD.org>; 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 <freebsd-gnats-submit@FreeBSD.org>; 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 <freebsd-gnats-submit@FreeBSD.org>; 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 <arundel@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] fix several rtprio(1) issues
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         154042
>Category:       bin
>Synopsis:       [patch] fix several rtprio(1) issues
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    delphij
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jan 15 22:20:09 UTC 2011
>Closed-Date:    Fri May 18 01:19:19 UTC 2012
>Last-Modified:  Fri May 18 01:19:19 UTC 2012
>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:
Responsible-Changed-From-To: freebsd-bugs->delphij 
Responsible-Changed-By: delphij 
Responsible-Changed-When: Tue Dec 27 11:02:51 UTC 2011 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=154042 
State-Changed-From-To: open->patched 
State-Changed-By: delphij 
State-Changed-When: Tue Dec 27 20:04:55 UTC 2011 
State-Changed-Why:  
Patch applied against -HEAD (with changes), MFC reminder. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=154042 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/154042: commit references a PR
Date: Tue, 27 Dec 2011 20:04:12 +0000 (UTC)

 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
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: Bugs Beastie <bugsbeastie@gmail.com>
To: bug-followup@FreeBSD.org, arundel@FreeBSD.org
Cc:  
Subject: Re: bin/154042: [patch] fix several rtprio(1) issues
Date: Fri, 11 May 2012 23:10:46 +0200

 --e89a8f23472587fd7304bfc92bcd
 Content-Type: multipart/alternative; boundary=e89a8f23472587fd7004bfc92bca
 
 --e89a8f23472587fd7004bfc92bca
 Content-Type: text/plain; charset=ISO-8859-1
 
 The change introduced in r228917 has badly broken the form of the
 [rt|id]prio commands:
 idprio priority command [arguments]
 
 This affects boinc, for example.
 The attached patch fixes the problem.
 
 --e89a8f23472587fd7004bfc92bca
 Content-Type: text/html; charset=ISO-8859-1
 
 The change introduced in r228917 has badly broken the form of the [rt|id]prio commands:<br>idprio priority command [arguments]<br><br>This affects boinc, for example.<br>The attached patch fixes the problem.<br>
 
 --e89a8f23472587fd7004bfc92bca--
 --e89a8f23472587fd7304bfc92bcd
 Content-Type: text/x-csrc; charset=US-ASCII; name="patch-rtprio.c"
 Content-Disposition: attachment; filename="patch-rtprio.c"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_h23qrk700
 
 LS0tIHJ0cHJpby5jLm9yaWcJMjAxMi0wNS0wMyAxNzoyODoyNi4wMDAwMDAwMDAgKzAyMDANCisr
 KyBydHByaW8uYwkyMDEyLTA1LTExIDIxOjMwOjU4LjAwMDAwMDAwMCArMDIwMA0KQEAgLTEwOSw5
 ICsxMDksMTEgQEANCiAJCWlmIChhcmd2WzJdWzBdID09ICctJykgew0KIAkJCXByb2MgPSBwYXJz
 ZWludChhcmd2WzJdLCAicGlkIik7DQogCQkJcHJvYyA9IGFicyhwcm9jKTsNCi0JCQlpZiAocnRw
 cmlvKFJUUF9TRVQsIHByb2MsICZydHApICE9IDApDQotCQkJCWVycigxLCAiUlRQX1NFVCIpOw0K
 LQkJfSBlbHNlIHsNCisJCX0NCisJCWlmIChydHByaW8oUlRQX1NFVCwgcHJvYywgJnJ0cCkgIT0g
 MCkNCisJCQllcnIoMSwgIlJUUF9TRVQiKTsNCisNCisJCWlmIChwcm9jID09IDApIHsNCiAJCQll
 eGVjdnAoYXJndlsyXSwgJmFyZ3ZbMl0pOw0KIAkJCWVycigxLCAiZXhlY3ZwOiAlcyIsIGFyZ3Zb
 Ml0pOw0KIAkJfQ0K
 --e89a8f23472587fd7304bfc92bcd--

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/154042: commit references a PR
Date: Fri, 18 May 2012 00:41:10 +0000 (UTC)

 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 <bugsbeastie gmail.com>
 
 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
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/154042: commit references a PR
Date: Fri, 18 May 2012 00:41:10 +0000 (UTC)

 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 <bugsbeastie gmail.com>
 
 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
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: delphij 
State-Changed-When: Fri May 18 01:19:04 UTC 2012 
State-Changed-Why:  
Committed, thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=154042 
>Unformatted:
