diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1999-03-04 16:14:59 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1999-03-04 16:14:59 +0000 |
commit | d2230d0c327a84c14104d20f9f9aa3f5e2e33163 (patch) | |
tree | 00a91f550dbee685e9466d34bafaa98aefab8122 /usr.bin/renice | |
parent | 6446c2d85ae88c0c6afa31f09bc02f44f5d9fcb2 (diff) |
catch things like "renice --19 6706" as an error, use warn/warnx and update sccs ids to 4.4lite while we are at it
Diffstat (limited to 'usr.bin/renice')
-rw-r--r-- | usr.bin/renice/renice.8 | 10 | ||||
-rw-r--r-- | usr.bin/renice/renice.c | 73 |
2 files changed, 49 insertions, 34 deletions
diff --git a/usr.bin/renice/renice.8 b/usr.bin/renice/renice.8 index 76ed2bdb778..f6bbcbe8640 100644 --- a/usr.bin/renice/renice.8 +++ b/usr.bin/renice/renice.8 @@ -1,6 +1,6 @@ -.\" $OpenBSD: renice.8,v 1.5 1998/09/27 16:57:51 aaron Exp $ -.\" Copyright (c) 1983, 1991 The Regents of the University of California. -.\" All rights reserved. +.\" $OpenBSD: renice.8,v 1.6 1999/03/04 16:14:58 millert Exp $ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -30,9 +30,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" from: @(#)renice.8 6.5 (Berkeley) 3/16/91 +.\" from: @(#)renice.8 8.1 (Berkeley) 6/9/93 .\" -.Dd March 16, 1991 +.Dd June 9, 1993 .Dt RENICE 8 .Os BSD 4 .Sh NAME diff --git a/usr.bin/renice/renice.c b/usr.bin/renice/renice.c index 1ca684b6c7c..d679b56686d 100644 --- a/usr.bin/renice/renice.c +++ b/usr.bin/renice/renice.c @@ -1,8 +1,8 @@ -/* $OpenBSD: renice.c,v 1.4 1998/12/20 01:13:33 deraadt Exp $ */ +/* $OpenBSD: renice.c,v 1.5 1999/03/04 16:14:58 millert Exp $ */ /* - * Copyright (c) 1983 The Regents of the University of California. - * All rights reserved. + * Copyright (c) 1983, 1989, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,24 +34,31 @@ */ #ifndef lint -char copyright[] = -"@(#) Copyright (c) 1989 The Regents of the University of California.\n\ - All rights reserved.\n"; +static char copyright[] = +"@(#) Copyright (c) 1983, 1989, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -/*static char sccsid[] = "from: @(#)renice.c 5.3 (Berkeley) 6/1/90";*/ -static char rcsid[] = "$OpenBSD: renice.c,v 1.4 1998/12/20 01:13:33 deraadt Exp $"; +#if 0 +static char sccsid[] = "@(#)renice.c 8.1 (Berkeley) 6/9/93"; +#else +static char rcsid[] = "$OpenBSD: renice.c,v 1.5 1999/03/04 16:14:58 millert Exp $"; +#endif #endif /* not lint */ #include <sys/types.h> #include <sys/time.h> #include <sys/resource.h> + #include <stdio.h> #include <stdlib.h> #include <pwd.h> +#include <err.h> +#include <errno.h> -int donice __P((int, int, int)); +int donice __P((int, uid_t, int)); +void usage __P((void)); /* * Change the priority (nice) of processes @@ -63,15 +70,16 @@ main(argc, argv) char **argv; { int which = PRIO_PROCESS; - int who = 0, prio, errs = 0; + int errs = 0; + long prio, who = 0; + char *ep; argc--, argv++; - if (argc < 2) { - fprintf(stderr, "usage: renice priority [[-p] pid ...] "); - fprintf(stderr, "[[-g] pgrp ...] [[-u] user ...]\n"); - exit(1); - } - prio = atoi(*argv); + if (argc < 2) + usage(); + prio = strtol(*argv, &ep, 10); + if (*ep != NULL) + usage(); argc--, argv++; if (prio > PRIO_MAX) prio = PRIO_MAX; @@ -94,42 +102,49 @@ 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); + who = strtol(*argv, &ep, 10); + if (*ep != NULL || who < 0) { + warnx("%s: bad value", *argv); continue; } } - errs += donice(which, who, prio); + errs += donice(which, (uid_t)who, (int)prio); } exit(errs != 0); } int donice(which, who, prio) - int which, who, prio; + int which; + uid_t who; + int prio; { int oldprio; - extern int errno; errno = 0, oldprio = getpriority(which, who); if (oldprio == -1 && errno) { - fprintf(stderr, "renice: %d: ", who); - perror("getpriority"); + warn("getpriority: %d", who); return (1); } if (setpriority(which, who, prio) < 0) { - fprintf(stderr, "renice: %d: ", who); - perror("setpriority"); + warn("setpriority: %d", who); return (1); } printf("%d: old priority %d, new priority %d\n", who, oldprio, prio); return (0); } + +void +usage() +{ + extern char *__progname; + + fprintf(stderr, "usage: %s priority [[-p] pid ...] [[-g] pgrp ...] " + "[[-u] user ...]\n", __progname); + exit(1); +} |