[BACK]Return to renice.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / renice

Diff for /src/usr.bin/renice/renice.c between version 1.4 and 1.5

version 1.4, 1998/12/20 01:13:33 version 1.5, 1999/03/04 16:14:58
Line 1 
Line 1 
 /*      $OpenBSD$       */  /*      $OpenBSD$       */
   
 /*  /*
  * Copyright (c) 1983 The Regents of the University of California.   * Copyright (c) 1983, 1989, 1993
  * All rights reserved.   *      The Regents of the University of California.  All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions   * modification, are permitted provided that the following conditions
Line 34 
Line 34 
  */   */
   
 #ifndef lint  #ifndef lint
 char copyright[] =  static char copyright[] =
 "@(#) Copyright (c) 1989 The Regents of the University of California.\n\  "@(#) Copyright (c) 1983, 1989, 1993\n\
  All rights reserved.\n";          The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */  #endif /* not lint */
   
 #ifndef lint  #ifndef lint
 /*static char sccsid[] = "from: @(#)renice.c    5.3 (Berkeley) 6/1/90";*/  #if 0
   static char sccsid[] = "@(#)renice.c    8.1 (Berkeley) 6/9/93";
   #else
 static char rcsid[] = "$OpenBSD$";  static char rcsid[] = "$OpenBSD$";
   #endif
 #endif /* not lint */  #endif /* not lint */
   
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/time.h>  #include <sys/time.h>
 #include <sys/resource.h>  #include <sys/resource.h>
   
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <pwd.h>  #include <pwd.h>
   #include <err.h>
   #include <errno.h>
   
 int donice __P((int, int, int));  int donice __P((int, uid_t, int));
   void usage __P((void));
   
 /*  /*
  * Change the priority (nice) of processes   * Change the priority (nice) of processes
Line 63 
Line 70 
         char **argv;          char **argv;
 {  {
         int which = PRIO_PROCESS;          int which = PRIO_PROCESS;
         int who = 0, prio, errs = 0;          int errs = 0;
           long prio, who = 0;
           char *ep;
   
         argc--, argv++;          argc--, argv++;
         if (argc < 2) {          if (argc < 2)
                 fprintf(stderr, "usage: renice priority [[-p] pid ...] ");                  usage();
                 fprintf(stderr, "[[-g] pgrp ...] [[-u] user ...]\n");          prio = strtol(*argv, &ep, 10);
                 exit(1);          if (*ep != NULL)
         }                  usage();
         prio = atoi(*argv);  
         argc--, argv++;          argc--, argv++;
         if (prio > PRIO_MAX)          if (prio > PRIO_MAX)
                 prio = PRIO_MAX;                  prio = PRIO_MAX;
Line 94 
Line 102 
                         register struct passwd *pwd = getpwnam(*argv);                          register struct passwd *pwd = getpwnam(*argv);
   
                         if (pwd == NULL) {                          if (pwd == NULL) {
                                 fprintf(stderr, "renice: %s: unknown user\n",                                  warnx("%s: unknown user", *argv);
                                         *argv);  
                                 continue;                                  continue;
                         }                          }
                         who = pwd->pw_uid;                          who = pwd->pw_uid;
                 } else {                  } else {
                         who = atoi(*argv);                          who = strtol(*argv, &ep, 10);
                         if (who < 0) {                          if (*ep != NULL || who < 0) {
                                 fprintf(stderr, "renice: %s: bad value\n",                                  warnx("%s: bad value", *argv);
                                         *argv);  
                                 continue;                                  continue;
                         }                          }
                 }                  }
                 errs += donice(which, who, prio);                  errs += donice(which, (uid_t)who, (int)prio);
         }          }
         exit(errs != 0);          exit(errs != 0);
 }  }
   
 int  int
 donice(which, who, prio)  donice(which, who, prio)
         int which, who, prio;          int which;
           uid_t who;
           int prio;
 {  {
         int oldprio;          int oldprio;
         extern int errno;  
   
         errno = 0, oldprio = getpriority(which, who);          errno = 0, oldprio = getpriority(which, who);
         if (oldprio == -1 && errno) {          if (oldprio == -1 && errno) {
                 fprintf(stderr, "renice: %d: ", who);                  warn("getpriority: %d", who);
                 perror("getpriority");  
                 return (1);                  return (1);
         }          }
         if (setpriority(which, who, prio) < 0) {          if (setpriority(which, who, prio) < 0) {
                 fprintf(stderr, "renice: %d: ", who);                  warn("setpriority: %d", who);
                 perror("setpriority");  
                 return (1);                  return (1);
         }          }
         printf("%d: old priority %d, new priority %d\n", who, oldprio, prio);          printf("%d: old priority %d, new priority %d\n", who, oldprio, prio);
         return (0);          return (0);
   }
   
   void
   usage()
   {
           extern char *__progname;
   
           fprintf(stderr, "usage: %s priority [[-p] pid ...] [[-g] pgrp ...] "
               "[[-u] user ...]\n", __progname);
           exit(1);
 }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5