bin/154042: [patch] fix several rtprio(1) issues

Alexander Best arundel at FreeBSD.org
Sat Jan 15 22:20:10 UTC 2011


>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 at 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:


More information about the freebsd-bugs mailing list