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-unsubscr...@freebsd.org"

Reply via email to