aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-07-01 16:42:27 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-07-01 16:42:27 +0200
commit922f6f51dba8ba710cac0679635ed811b2139a53 (patch)
tree579ec114ed4608c99634b03bbcabfd94afd6e1bd
parentcd0f6b0c939e5098410ddb171db8c4a26cf8d623 (diff)
downloadbusybox-w32-922f6f51dba8ba710cac0679635ed811b2139a53.tar.gz
busybox-w32-922f6f51dba8ba710cac0679635ed811b2139a53.tar.bz2
busybox-w32-922f6f51dba8ba710cac0679635ed811b2139a53.zip
chrt: code shrink
function old new delta show_min_max 80 60 -20 packed_usage 26929 26896 -33 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-53) Total: -53 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/usage.src.h74
-rw-r--r--miscutils/chrt.c20
2 files changed, 48 insertions, 46 deletions
diff --git a/include/usage.src.h b/include/usage.src.h
index 53ee7943a..94a3256b1 100644
--- a/include/usage.src.h
+++ b/include/usage.src.h
@@ -434,7 +434,7 @@ INSERT
434 " [-/ DIR] [-n NICE] [-m BYTES] [-d BYTES] [-o N]\n" \ 434 " [-/ DIR] [-n NICE] [-m BYTES] [-d BYTES] [-o N]\n" \
435 " [-p N] [-f BYTES] [-c BYTES] PROG ARGS" 435 " [-p N] [-f BYTES] [-c BYTES] PROG ARGS"
436#define chpst_full_usage "\n\n" \ 436#define chpst_full_usage "\n\n" \
437 "Change the process state and run PROG\n" \ 437 "Change the process state, run PROG\n" \
438 "\nOptions:" \ 438 "\nOptions:" \
439 "\n -u USER[:GRP] Set uid and gid" \ 439 "\n -u USER[:GRP] Set uid and gid" \
440 "\n -U USER[:GRP] Set $UID and $GID in environment" \ 440 "\n -U USER[:GRP] Set $UID and $GID in environment" \
@@ -457,17 +457,17 @@ INSERT
457#define setuidgid_trivial_usage \ 457#define setuidgid_trivial_usage \
458 "USER PROG ARGS" 458 "USER PROG ARGS"
459#define setuidgid_full_usage "\n\n" \ 459#define setuidgid_full_usage "\n\n" \
460 "Set uid and gid to USER's uid and gid, removing all supplementary\n" \ 460 "Set uid and gid to USER's uid and gid, drop supplementary group ids,\n" \
461 "groups and run PROG" 461 "run PROG"
462#define envuidgid_trivial_usage \ 462#define envuidgid_trivial_usage \
463 "USER PROG ARGS" 463 "USER PROG ARGS"
464#define envuidgid_full_usage "\n\n" \ 464#define envuidgid_full_usage "\n\n" \
465 "Set $UID to USER's uid and $GID to USER's gid and run PROG" 465 "Set $UID to USER's uid and $GID to USER's gid, run PROG"
466#define envdir_trivial_usage \ 466#define envdir_trivial_usage \
467 "DIR PROG ARGS" 467 "DIR PROG ARGS"
468#define envdir_full_usage "\n\n" \ 468#define envdir_full_usage "\n\n" \
469 "Set various environment variables as specified by files\n" \ 469 "Set various environment variables as specified by files\n" \
470 "in the directory dir and run PROG" 470 "in the directory DIR, run PROG"
471#define softlimit_trivial_usage \ 471#define softlimit_trivial_usage \
472 "[-a BYTES] [-m BYTES] [-d BYTES] [-s BYTES] [-l BYTES]\n" \ 472 "[-a BYTES] [-m BYTES] [-d BYTES] [-s BYTES] [-l BYTES]\n" \
473 " [-f BYTES] [-c BYTES] [-r BYTES] [-o N] [-p N] [-t N]\n" \ 473 " [-f BYTES] [-c BYTES] [-r BYTES] [-o N] [-p N] [-t N]\n" \
@@ -538,24 +538,49 @@ INSERT
538#define bbconfig_trivial_usage \ 538#define bbconfig_trivial_usage \
539 "" 539 ""
540#define bbconfig_full_usage "\n\n" \ 540#define bbconfig_full_usage "\n\n" \
541 "Print the config file which built busybox" 541 "Print the config file used by busybox build"
542 542
543#define chrt_trivial_usage \ 543#define chrt_trivial_usage \
544 "[OPTIONS] [PRIO] [PID | PROG ARGS]" 544 "[OPTIONS] [PRIO] [PID | PROG ARGS]"
545#define chrt_full_usage "\n\n" \ 545#define chrt_full_usage "\n\n" \
546 "Manipulate real-time attributes of a process\n" \ 546 "Change scheduling priority and class for a process\n" \
547 "\nOptions:" \ 547 "\nOptions:" \
548 "\n -p Operate on PID" \ 548 "\n -p Operate on PID" \
549 "\n -r Set SCHED_RR scheduling" \ 549 "\n -r Set SCHED_RR class" \
550 "\n -f Set SCHED_FIFO scheduling" \ 550 "\n -f Set SCHED_FIFO class" \
551 "\n -o Set SCHED_OTHER scheduling" \ 551 "\n -o Set SCHED_OTHER class" \
552 "\n -m Show min and max priorities" \ 552 "\n -m Show min/max priorities" \
553 553
554#define chrt_example_usage \ 554#define chrt_example_usage \
555 "$ chrt -r 4 sleep 900; x=$!\n" \ 555 "$ chrt -r 4 sleep 900; x=$!\n" \
556 "$ chrt -f -p 3 $x\n" \ 556 "$ chrt -f -p 3 $x\n" \
557 "You need CAP_SYS_NICE privileges to set scheduling attributes of a process" 557 "You need CAP_SYS_NICE privileges to set scheduling attributes of a process"
558 558
559#define nice_trivial_usage \
560 "[-n ADJUST] [PROG ARGS]"
561#define nice_full_usage "\n\n" \
562 "Change scheduling priority, run PROG\n" \
563 "\nOptions:" \
564 "\n -n ADJUST Adjust priority by ADJUST" \
565
566#define renice_trivial_usage \
567 "{{-n INCREMENT} | PRIORITY} [[-p | -g | -u] ID...]"
568#define renice_full_usage "\n\n" \
569 "Change scheduling priority for a running process\n" \
570 "\nOptions:" \
571 "\n -n Adjust current nice value (smaller is faster)" \
572 "\n -p Process id(s) (default)" \
573 "\n -g Process group id(s)" \
574 "\n -u Process user name(s) and/or id(s)" \
575
576#define ionice_trivial_usage \
577 "[-c 1-3] [-n 0-7] [-p PID] [PROG]"
578#define ionice_full_usage "\n\n" \
579 "Change I/O priority and class\n" \
580 "\nOptions:" \
581 "\n -c Class. 1:realtime 2:best-effort 3:idle" \
582 "\n -n Priority" \
583
559#define cp_trivial_usage \ 584#define cp_trivial_usage \
560 "[OPTIONS] SOURCE DEST" 585 "[OPTIONS] SOURCE DEST"
561#define cp_full_usage "\n\n" \ 586#define cp_full_usage "\n\n" \
@@ -1299,7 +1324,7 @@ INSERT
1299#define flock_trivial_usage \ 1324#define flock_trivial_usage \
1300 "[-sxun] FD|{FILE [-c] PROG ARGS}" 1325 "[-sxun] FD|{FILE [-c] PROG ARGS}"
1301#define flock_full_usage "\n\n" \ 1326#define flock_full_usage "\n\n" \
1302 "[Un]lock file descriptor, or lock FILE and run PROG\n" \ 1327 "[Un]lock file descriptor, or lock FILE, run PROG\n" \
1303 "\nOptions:" \ 1328 "\nOptions:" \
1304 "\n -s Shared lock" \ 1329 "\n -s Shared lock" \
1305 "\n -x Exclusive lock (default)" \ 1330 "\n -x Exclusive lock (default)" \
@@ -2038,14 +2063,6 @@ INSERT
2038 "\n -Z Set security context" \ 2063 "\n -Z Set security context" \
2039 ) 2064 )
2040 2065
2041#define ionice_trivial_usage \
2042 "[-c 1-3] [-n 0-7] [-p PID] [PROG]"
2043#define ionice_full_usage "\n\n" \
2044 "Change I/O scheduling class and priority\n" \
2045 "\nOptions:" \
2046 "\n -c Class. 1:realtime 2:best-effort 3:idle" \
2047 "\n -n Priority" \
2048
2049/* would need to make the " | " optional depending on more than one selected: */ 2066/* would need to make the " | " optional depending on more than one selected: */
2050#define ip_trivial_usage \ 2067#define ip_trivial_usage \
2051 "[OPTIONS] {" \ 2068 "[OPTIONS] {" \
@@ -2965,13 +2982,6 @@ INSERT
2965 "\n -p Display PID/Program name for sockets" \ 2982 "\n -p Display PID/Program name for sockets" \
2966 ) 2983 )
2967 2984
2968#define nice_trivial_usage \
2969 "[-n ADJUST] [PROG ARGS]"
2970#define nice_full_usage "\n\n" \
2971 "Run PROG with modified scheduling priority\n" \
2972 "\nOptions:" \
2973 "\n -n ADJUST Adjust priority by ADJUST" \
2974
2975#define nmeter_trivial_usage \ 2985#define nmeter_trivial_usage \
2976 "format_string" 2986 "format_string"
2977#define nmeter_full_usage "\n\n" \ 2987#define nmeter_full_usage "\n\n" \
@@ -3425,16 +3435,6 @@ INSERT
3425 "\n" \ 3435 "\n" \
3426 "\nOther options are silently ignored" \ 3436 "\nOther options are silently ignored" \
3427 3437
3428#define renice_trivial_usage \
3429 "{{-n INCREMENT} | PRIORITY} [[-p | -g | -u] ID...]"
3430#define renice_full_usage "\n\n" \
3431 "Change priority of running processes\n" \
3432 "\nOptions:" \
3433 "\n -n Adjust current nice value (smaller is faster)" \
3434 "\n -p Process id(s) (default)" \
3435 "\n -g Process group id(s)" \
3436 "\n -u Process user name(s) and/or id(s)" \
3437
3438#define scriptreplay_trivial_usage \ 3438#define scriptreplay_trivial_usage \
3439 "timingfile [typescript [divisor]]" 3439 "timingfile [typescript [divisor]]"
3440#define scriptreplay_full_usage "\n\n" \ 3440#define scriptreplay_full_usage "\n\n" \
diff --git a/miscutils/chrt.c b/miscutils/chrt.c
index e2b7f8ae0..3d0da58ca 100644
--- a/miscutils/chrt.c
+++ b/miscutils/chrt.c
@@ -5,33 +5,35 @@
5 * 5 *
6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
7 */ 7 */
8
9#include <sched.h> 8#include <sched.h>
10#include "libbb.h" 9#include "libbb.h"
11#ifndef _POSIX_PRIORITY_SCHEDULING 10#ifndef _POSIX_PRIORITY_SCHEDULING
12#warning your system may be foobared 11#warning your system may be foobared
13#endif 12#endif
13
14static const struct { 14static const struct {
15 int policy; 15 int policy;
16 char name[12]; 16 char name[sizeof("SCHED_OTHER")];
17} policies[] = { 17} policies[] = {
18 {SCHED_OTHER, "SCHED_OTHER"}, 18 {SCHED_OTHER, "SCHED_OTHER"},
19 {SCHED_FIFO, "SCHED_FIFO"}, 19 {SCHED_FIFO, "SCHED_FIFO"},
20 {SCHED_RR, "SCHED_RR"} 20 {SCHED_RR, "SCHED_RR"}
21}; 21};
22 22
23//TODO: add
24// -b, SCHED_BATCH
25// -i, SCHED_IDLE
26
23static void show_min_max(int pol) 27static void show_min_max(int pol)
24{ 28{
25 const char *fmt = "%s min/max priority\t: %d/%d\n\0%s not supported?\n"; 29 const char *fmt = "%s min/max priority\t: %u/%u\n";
26 int max, min; 30 int max, min;
31
27 max = sched_get_priority_max(pol); 32 max = sched_get_priority_max(pol);
28 min = sched_get_priority_min(pol); 33 min = sched_get_priority_min(pol);
29 if (max >= 0 && min >= 0) 34 if ((max|min) < 0)
30 printf(fmt, policies[pol].name, min, max); 35 fmt = "%s not supported\n";
31 else { 36 printf(fmt, policies[pol].name, min, max);
32 fmt += 29;
33 printf(fmt, policies[pol].name);
34 }
35} 37}
36 38
37#define OPT_m (1<<0) 39#define OPT_m (1<<0)