diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-19 02:53:32 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-19 02:53:32 +0000 |
commit | bea0037dbdd979603fb0b5be8b43f5478c1f6fec (patch) | |
tree | 5776ae3af5a3e83d41c7087f70713952b6360988 /src/skaembutils/s6-nice.c | |
download | s6-portable-utils-bea0037dbdd979603fb0b5be8b43f5478c1f6fec.tar.gz s6-portable-utils-bea0037dbdd979603fb0b5be8b43f5478c1f6fec.tar.xz s6-portable-utils-bea0037dbdd979603fb0b5be8b43f5478c1f6fec.zip |
initial commit
Diffstat (limited to 'src/skaembutils/s6-nice.c')
-rw-r--r-- | src/skaembutils/s6-nice.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/skaembutils/s6-nice.c b/src/skaembutils/s6-nice.c new file mode 100644 index 0000000..ec9f477 --- /dev/null +++ b/src/skaembutils/s6-nice.c @@ -0,0 +1,46 @@ +/* ISC license. */ + +#include <unistd.h> +#include <errno.h> +#include <skalibs/sgetopt.h> +#include <skalibs/uint.h> +#include <skalibs/fmtscan.h> +#include <skalibs/strerr2.h> +#include <skalibs/djbunix.h> + +#define USAGE "s6-nice [ -I | -i ] [ -n value ] prog..." + +int main (int argc, char const *const *argv, char const *const *envp) +{ + int incr = 10 ; + int strict = 0 ; + PROG = "s6-nice" ; + { + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + register int opt = subgetopt_r(argc, argv, "Iin:", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'I' : strict = 0 ; break ; + case 'i' : strict = 1 ; break ; + case 'n': if (!int_scan(l.arg, &incr)) strerr_dieusage(100, USAGE) ; break ; + default : strerr_dieusage(100, USAGE) ; + } + } + argc -= l.ind ; argv += l.ind ; + } + if (!argc) strerr_dieusage(100, USAGE) ; + + errno = 0 ; + if ((nice(incr) < 0) && errno) + { + char fmt[1+UINT_FMT] ; + fmt[int_fmt(fmt, incr)] = 0 ; + if (strict) strerr_diefu2sys(111, "nice to ", fmt) ; + else strerr_warnwu2sys("nice to ", fmt) ; + } + pathexec_run(argv[0], argv, envp) ; + strerr_dieexec((errno == ENOENT) ? 127 : 126, argv[0]) ; +} |