2013-06-09 13:20:55 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2013-06-11 18:33:52 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
2013-06-09 13:20:55 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2013-06-11 18:33:52 +00:00
|
|
|
#include <unistd.h>
|
2013-06-09 13:20:55 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2013-06-11 18:33:52 +00:00
|
|
|
static void eusage(void);
|
2013-06-09 13:20:55 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2013-06-11 18:33:52 +00:00
|
|
|
long val = 10;
|
2013-06-09 13:20:55 +00:00
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
case 'n':
|
2013-06-11 18:33:52 +00:00
|
|
|
val = estrtol(EARGF(eusage()), 10);
|
2013-06-09 13:20:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-06-11 18:33:52 +00:00
|
|
|
eusage();
|
|
|
|
break;
|
2013-06-09 13:20:55 +00:00
|
|
|
} ARGEND;
|
|
|
|
|
2013-06-11 18:33:52 +00:00
|
|
|
if(argc == 0)
|
|
|
|
eusage();
|
2013-06-09 13:20:55 +00:00
|
|
|
|
2013-06-11 18:33:52 +00:00
|
|
|
errno = 0;
|
|
|
|
nice((int)MAX(INT_MIN, MIN(val, INT_MAX)));
|
|
|
|
if(errno != 0)
|
|
|
|
perror("can't adjust niceness");
|
2013-06-09 13:20:55 +00:00
|
|
|
|
2013-06-11 18:33:52 +00:00
|
|
|
/* POSIX specifies the nice failure still invokes the command */
|
|
|
|
execvp(argv[0], argv);
|
|
|
|
/* reached only on failure */
|
|
|
|
perror(argv[0]);
|
|
|
|
return (errno == ENOENT)? 127 : 126;
|
2013-06-09 13:20:55 +00:00
|
|
|
}
|
|
|
|
|
2013-06-11 18:33:52 +00:00
|
|
|
static void
|
|
|
|
eusage(void)
|
|
|
|
{
|
|
|
|
eprintf("usage: nice [-n inc] command [options ...]\n");
|
|
|
|
}
|