diff options
author | 2014-02-13 20:51:10 +0000 | |
---|---|---|
committer | 2014-02-13 20:51:10 +0000 | |
commit | 40d18421c2779dbde0b9e56faed068499226b852 (patch) | |
tree | ec7e821717087753eb76214d9387dcedf895e457 | |
parent | small style fix from jan stary (diff) | |
download | wireguard-openbsd-40d18421c2779dbde0b9e56faed068499226b852.tar.xz wireguard-openbsd-40d18421c2779dbde0b9e56faed068499226b852.zip |
use strotonum
-rw-r--r-- | usr.bin/nice/nice.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/usr.bin/nice/nice.c b/usr.bin/nice/nice.c index 398b00b54d7..e992069c745 100644 --- a/usr.bin/nice/nice.c +++ b/usr.bin/nice/nice.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nice.c,v 1.13 2014/02/13 20:43:29 tedu Exp $ */ +/* $OpenBSD: nice.c,v 1.14 2014/02/13 20:51:10 tedu Exp $ */ /* $NetBSD: nice.c,v 1.9 1995/08/31 23:30:58 jtc Exp $ */ /* @@ -47,14 +47,18 @@ static void usage(void); int main(int argc, char *argv[]) { - int niceness = DEFNICE; + const char *errstr; + int prio = DEFNICE; int c; setlocale(LC_ALL, ""); /* handle obsolete -number syntax */ - if (argc > 1 && argv[1][0] == '-' && isdigit((unsigned char)argv[1][1])) { - niceness = atoi(argv[1] + 1); + if (argc > 1 && argv[1][0] == '-' && + isdigit((unsigned char)argv[1][1])) { + prio = strtonum(argv[1] + 1, PRIO_MIN, PRIO_MAX, &errstr); + if (errstr) + errx(1, "increment is %s", errstr); argc--; argv++; } @@ -62,9 +66,10 @@ main(int argc, char *argv[]) while ((c = getopt (argc, argv, "n:")) != -1) { switch (c) { case 'n': - niceness = atoi(optarg); + prio = strtonum(optarg, PRIO_MIN, PRIO_MAX, &errstr); + if (errstr) + errx(1, "increment is %s", errstr); break; - case '?': default: usage(); @@ -78,12 +83,12 @@ main(int argc, char *argv[]) usage(); errno = 0; - niceness += getpriority(PRIO_PROCESS, 0); + prio += getpriority(PRIO_PROCESS, 0); if (errno) { err(1, "getpriority"); /* NOTREACHED */ } - if (setpriority(PRIO_PROCESS, 0, niceness)) + if (setpriority(PRIO_PROCESS, 0, prio)) warn("setpriority"); execvp(argv[0], &argv[0]); |