Use err(3). Add usage() and prototypes.

This commit is contained in:
Philippe Charnier 1997-08-05 06:42:48 +00:00
parent 321e481502
commit 0bb6b796dd

View File

@ -32,27 +32,37 @@
*/ */
#ifndef lint #ifndef lint
static char copyright[] = static const char copyright[] =
"@(#) Copyright (c) 1983, 1989, 1993\n\ "@(#) Copyright (c) 1983, 1989, 1993\n\
The Regents of the University of California. 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
#if 0
static char sccsid[] = "@(#)renice.c 8.1 (Berkeley) 6/9/93"; static char sccsid[] = "@(#)renice.c 8.1 (Berkeley) 6/9/93";
#endif
static const char rcsid[] =
"$Id$";
#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 <err.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <pwd.h> #include <pwd.h>
int donice __P((int, int, int));
static void usage __P((void));
/* /*
* Change the priority (nice) of processes * Change the priority (nice) of processes
* or groups of processes which are already * or groups of processes which are already
* running. * running.
*/ */
int
main(argc, argv) main(argc, argv)
char **argv; char **argv;
{ {
@ -60,11 +70,8 @@ main(argc, argv)
int who = 0, prio, errs = 0; int who = 0, prio, errs = 0;
argc--, argv++; argc--, argv++;
if (argc < 2) { if (argc < 2)
fprintf(stderr, "usage: renice priority [ [ -p ] pids ] "); usage();
fprintf(stderr, "[ [ -g ] pgrps ] [ [ -u ] users ]\n");
exit(1);
}
prio = atoi(*argv); prio = atoi(*argv);
argc--, argv++; argc--, argv++;
if (prio > PRIO_MAX) if (prio > PRIO_MAX)
@ -88,16 +95,14 @@ main(argc, argv)
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 = atoi(*argv);
if (who < 0) { if (who < 0) {
fprintf(stderr, "renice: %s: bad value\n", warnx("%s: bad value", *argv);
*argv);
continue; continue;
} }
} }
@ -106,6 +111,15 @@ main(argc, argv)
exit(errs != 0); exit(errs != 0);
} }
static void
usage()
{
fprintf(stderr,
"usage: renice priority [ [ -p ] pids ] [ [ -g ] pgrps ] [ [ -u ] users ]\n");
exit(1);
}
int
donice(which, who, prio) donice(which, who, prio)
int which, who, prio; int which, who, prio;
{ {
@ -114,13 +128,11 @@ donice(which, who, prio)
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("%d: getpriority", 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("%d: setpriority", 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);