Don't core dump when invoked with no arguments.

Understand negative priorities.
This commit is contained in:
jtc 1993-07-12 22:04:01 +00:00
parent 5fb0979e45
commit 3ae2e662e7
1 changed files with 7 additions and 4 deletions

View File

@ -45,6 +45,7 @@ static char sccsid[] = "@(#)nice.c 5.4 (Berkeley) 6/1/90";
#include <sys/resource.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define DEFNICE 10
@ -55,11 +56,13 @@ main(argc, argv)
{
extern int errno;
int niceness;
char *strerror();
if (!argv[1])
usage();
niceness = DEFNICE;
if (argv[1][0] == '-')
if (isdigit(argv[1][1])) {
if (isdigit(argv[1][1]) || argv[1][1] == '-') {
niceness = atoi(argv[1] + 1);
++argv;
}
@ -80,8 +83,8 @@ main(argc, argv)
exit(1);
}
if (setpriority(PRIO_PROCESS, 0, niceness)) {
(void)fprintf(stderr,
"nice: setpriority: %s\n", strerror(errno));
(void)fprintf(stderr, "nice: setpriority: %s\n",
strerror(errno));
exit(1);
}
execvp(argv[1], &argv[1]);