string.h is ANSI C include file
[unix-history] / usr / src / usr.bin / renice / renice.c
index 4a55040..c9e5ac5 100644 (file)
@@ -1,6 +1,29 @@
+/*
+ * Copyright (c) 1983 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)renice.c    4.3 (Berkeley) 83/07/02";
-#endif
+char copyright[] =
+"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)renice.c   5.2 (Berkeley) %G%";
+#endif /* not lint */
 
 #include <sys/time.h>
 #include <sys/resource.h>
 
 #include <sys/time.h>
 #include <sys/resource.h>
@@ -19,14 +42,10 @@ main(argc, argv)
        int who = 0, prio, errs = 0;
 
        argc--, argv++;
        int who = 0, prio, errs = 0;
 
        argc--, argv++;
-       if (argc < 2)
-               usage();
-       if (strcmp(*argv, "-g") == 0) {
-               which = PRIO_PGRP;
-               argv++, argc--;
-       } else if (strcmp(*argv, "-u") == 0) {
-               which = PRIO_USER;
-               argv++, argc--;
+       if (argc < 2) {
+               fprintf(stderr, "usage: renice priority [ [ -p ] pids ] ");
+               fprintf(stderr, "[ [ -g ] pgrps ] [ [ -u ] users ]\n");
+               exit(1);
        }
        prio = atoi(*argv);
        argc--, argv++;
        }
        prio = atoi(*argv);
        argc--, argv++;
@@ -34,9 +53,19 @@ main(argc, argv)
                prio = PRIO_MAX;
        if (prio < PRIO_MIN)
                prio = PRIO_MIN;
                prio = PRIO_MAX;
        if (prio < PRIO_MIN)
                prio = PRIO_MIN;
-       if (argc == 0)
-               errs += donice(which, 0, prio);
        for (; argc > 0; argc--, argv++) {
        for (; argc > 0; argc--, argv++) {
+               if (strcmp(*argv, "-g") == 0) {
+                       which = PRIO_PGRP;
+                       continue;
+               }
+               if (strcmp(*argv, "-u") == 0) {
+                       which = PRIO_USER;
+                       continue;
+               }
+               if (strcmp(*argv, "-p") == 0) {
+                       which = PRIO_PROCESS;
+                       continue;
+               }
                if (which == PRIO_USER) {
                        register struct passwd *pwd = getpwnam(*argv);
                        
                if (which == PRIO_USER) {
                        register struct passwd *pwd = getpwnam(*argv);
                        
@@ -62,9 +91,10 @@ main(argc, argv)
 donice(which, who, prio)
        int which, who, prio;
 {
 donice(which, who, prio)
        int which, who, prio;
 {
-       int oldprio = getpriority(which, who);
+       int oldprio;
        extern int errno;
 
        extern int errno;
 
+       errno = 0, oldprio = getpriority(which, who);
        if (oldprio == -1 && errno) {
                fprintf(stderr, "renice: %d: ", who);
                perror("getpriority");
        if (oldprio == -1 && errno) {
                fprintf(stderr, "renice: %d: ", who);
                perror("getpriority");
@@ -78,11 +108,3 @@ donice(which, who, prio)
        printf("%d: old priority %d, new priority %d\n", who, oldprio, prio);
        return (0);
 }
        printf("%d: old priority %d, new priority %d\n", who, oldprio, prio);
        return (0);
 }
-
-usage()
-{
-       fprintf(stderr, "usage: renice priority [ pid .... ]\n");
-       fprintf(stderr, "or, renice -g priority [ pgrp .... ]\n");
-       fprintf(stderr, "or, renice -u priority [ user .... ]\n");
-       exit(1);
-}