mirror of
https://github.com/sheumann/hush.git
synced 2024-12-30 05:29:47 +00:00
21e8e8da64
function old new delta BB_EXECVP_or_die - 47 +47 time_main 1042 1043 +1 chrt_main 371 364 -7 ionice_main 292 282 -10 setsid_main 69 56 -13 nohup_main 236 223 -13 cttyhack_main 266 253 -13 chroot_main 94 81 -13 chpst_main 746 733 -13 timeout_main 297 279 -18 taskset_main 541 522 -19 vfork_child 67 45 -22 parse 975 953 -22 lpd_main 770 748 -22 launch_helper 192 170 -22 tcpudpsvd_main 1810 1782 -28 nice_main 190 156 -34 env_main 242 206 -36 run_command 221 174 -47 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/17 up/down: 48/-352) Total: -304 bytes Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
52 lines
1.2 KiB
C
52 lines
1.2 KiB
C
/* vi: set sw=4 ts=4: */
|
|
/*
|
|
* nice implementation for busybox
|
|
*
|
|
* Copyright (C) 2005 Manuel Novoa III <mjn3@codepoet.org>
|
|
*
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
|
*/
|
|
|
|
#include <sys/resource.h>
|
|
#include "libbb.h"
|
|
|
|
int nice_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
int nice_main(int argc, char **argv)
|
|
{
|
|
int old_priority, adjustment;
|
|
|
|
old_priority = getpriority(PRIO_PROCESS, 0);
|
|
|
|
if (!*++argv) { /* No args, so (GNU) output current nice value. */
|
|
printf("%d\n", old_priority);
|
|
fflush_stdout_and_exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
adjustment = 10; /* Set default adjustment. */
|
|
|
|
if (argv[0][0] == '-') {
|
|
if (argv[0][1] == 'n') { /* -n */
|
|
if (argv[0][2]) { /* -nNNNN (w/o space) */
|
|
argv[0] += 2; argv--; argc++;
|
|
}
|
|
} else { /* -NNN (NNN may be negative) == -n NNN */
|
|
argv[0] += 1; argv--; argc++;
|
|
}
|
|
if (argc < 4) { /* Missing priority and/or utility! */
|
|
bb_show_usage();
|
|
}
|
|
adjustment = xatoi_range(argv[1], INT_MIN/2, INT_MAX/2);
|
|
argv += 2;
|
|
}
|
|
|
|
{ /* Set our priority. */
|
|
int prio = old_priority + adjustment;
|
|
|
|
if (setpriority(PRIO_PROCESS, 0, prio) < 0) {
|
|
bb_perror_msg_and_die("setpriority(%d)", prio);
|
|
}
|
|
}
|
|
|
|
BB_EXECVP_or_die(argv);
|
|
}
|