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