Various fixes, add renice command.
This commit adds the renice command and its man page, it also introduces some fixes: * Makes nice command more solid, it also makes it respect POSIX return values. * Fixes estrtol, which produced a misleading error on out of range errors. * Fixes chgrp.1 NAME section. Signed-off-by: Christoph Lohmann <20h@r-36.net>
This commit is contained in:
committed by
Christoph Lohmann
parent
c3b771d682
commit
75c97de593
42
nice.c
42
nice.c
@@ -1,38 +1,44 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "util.h"
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
eprintf("usage: nice [-n inc] command [options ...]\n");
|
||||
}
|
||||
static void eusage(void);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int inc = 10;
|
||||
long val = 10;
|
||||
|
||||
ARGBEGIN {
|
||||
case 'n':
|
||||
inc = atoi(EARGF(usage()));
|
||||
val = estrtol(EARGF(eusage()), 10);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
eusage();
|
||||
break;
|
||||
} ARGEND;
|
||||
|
||||
nice(inc); /* POSIX specifies the nice failure still invokes the command. */
|
||||
if(argc == 0)
|
||||
eusage();
|
||||
|
||||
if(!*argv)
|
||||
usage();
|
||||
errno = 0;
|
||||
nice((int)MAX(INT_MIN, MIN(val, INT_MAX)));
|
||||
if(errno != 0)
|
||||
perror("can't adjust niceness");
|
||||
|
||||
execvp(*argv, argv);
|
||||
eprintf("nice: '%s': %s\n", *argv, strerror(errno));
|
||||
|
||||
return EXIT_FAILURE;
|
||||
/* 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;
|
||||
}
|
||||
|
||||
static void
|
||||
eusage(void)
|
||||
{
|
||||
eprintf("usage: nice [-n inc] command [options ...]\n");
|
||||
}
|
||||
|
Reference in New Issue
Block a user