diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-17 09:29:43 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-03-17 09:29:43 +0000 |
commit | b44c790e41e281965955a83408f35ea53ecdb3d2 (patch) | |
tree | 98514dba64f7b74b9d60882bfeca1e2c4976b033 /miscutils/chrt.c | |
parent | d25c33f186c7cf3618c34ce79af94fe156f9ab02 (diff) | |
download | busybox-w32-b44c790e41e281965955a83408f35ea53ecdb3d2.tar.gz busybox-w32-b44c790e41e281965955a83408f35ea53ecdb3d2.tar.bz2 busybox-w32-b44c790e41e281965955a83408f35ea53ecdb3d2.zip |
*: fix various kinds of damage to letter 'c' in Arkadiusz Mickiewicz' surname.
chrt,taskset,dc,eject: shrink
crontab: call "vi" with just name, no path
watchdog: intercept all fatal signals
function old new delta
xstrtoull_range - 35 +35
static.sg_commands - 18 +18
packed_usage 23698 23712 +14
watchdog_main 148 151 +3
crontab_main 637 638 +1
base 1 - -1
static.ps 4 - -4
pointer 4 - -4
stack_machine 99 92 -7
run_command 273 260 -13
eject_main 360 343 -17
static.C 30 12 -18
ptok 61 38 -23
xstrtol_range 27 - -27
get_token 35 - -35
taskset_main 586 550 -36
chrt_main 411 372 -39
dc_main 158 117 -41
time_main 1127 1037 -90
------------------------------------------------------------------------------
(add/remove: 2/5 grow/shrink: 3/9 up/down: 71/-355) Total: -284 bytes
text data bss dec hex filename
793680 662 7420 801762 c3be2 busybox_old
793327 662 7412 801401 c3a79 busybox_unstripped
Diffstat (limited to 'miscutils/chrt.c')
-rw-r--r-- | miscutils/chrt.c | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/miscutils/chrt.c b/miscutils/chrt.c index 418e7ae79..0d55e3299 100644 --- a/miscutils/chrt.c +++ b/miscutils/chrt.c | |||
@@ -13,8 +13,8 @@ | |||
13 | #warning your system may be foobared | 13 | #warning your system may be foobared |
14 | #endif | 14 | #endif |
15 | static const struct { | 15 | static const struct { |
16 | const int policy; | 16 | int policy; |
17 | const char const name[12]; | 17 | char name[12]; |
18 | } policies[] = { | 18 | } policies[] = { |
19 | {SCHED_OTHER, "SCHED_OTHER"}, | 19 | {SCHED_OTHER, "SCHED_OTHER"}, |
20 | {SCHED_FIFO, "SCHED_FIFO"}, | 20 | {SCHED_FIFO, "SCHED_FIFO"}, |
@@ -42,83 +42,83 @@ static void show_min_max(int pol) | |||
42 | #define OPT_o (1<<4) | 42 | #define OPT_o (1<<4) |
43 | 43 | ||
44 | int chrt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 44 | int chrt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
45 | int chrt_main(int argc, char **argv) | 45 | int chrt_main(int argc ATTRIBUTE_UNUSED, char **argv) |
46 | { | 46 | { |
47 | pid_t pid = 0; | 47 | pid_t pid = 0; |
48 | unsigned opt; | 48 | unsigned opt; |
49 | struct sched_param sp; | 49 | struct sched_param sp; |
50 | char *p_opt = NULL, *priority = NULL; | 50 | char *pid_str; |
51 | const char *state = "current\0new"; | 51 | char *priority = priority; /* for compiler */ |
52 | int prio = 0, policy = SCHED_RR; | 52 | const char *current_new; |
53 | int policy = SCHED_RR; | ||
53 | 54 | ||
54 | opt_complementary = "r--fo:f--ro:r--fo"; /* only one policy accepted */ | 55 | /* at least 1 arg; only one policy accepted */ |
55 | opt = getopt32(argv, "+mp:rfo", &p_opt); | 56 | opt_complementary = "-1:r--fo:f--ro:r--fo"; |
57 | opt = getopt32(argv, "+mprfo"); | ||
56 | if (opt & OPT_r) | 58 | if (opt & OPT_r) |
57 | policy = SCHED_RR; | 59 | policy = SCHED_RR; |
58 | if (opt & OPT_f) | 60 | if (opt & OPT_f) |
59 | policy = SCHED_FIFO; | 61 | policy = SCHED_FIFO; |
60 | if (opt & OPT_o) | 62 | if (opt & OPT_o) |
61 | policy = SCHED_OTHER; | 63 | policy = SCHED_OTHER; |
62 | |||
63 | if (opt & OPT_m) { /* print min/max */ | 64 | if (opt & OPT_m) { /* print min/max */ |
64 | show_min_max(SCHED_FIFO); | 65 | show_min_max(SCHED_FIFO); |
65 | show_min_max(SCHED_RR); | 66 | show_min_max(SCHED_RR); |
66 | show_min_max(SCHED_OTHER); | 67 | show_min_max(SCHED_OTHER); |
67 | fflush_stdout_and_exit(EXIT_SUCCESS); | 68 | fflush_stdout_and_exit(EXIT_SUCCESS); |
68 | } | 69 | } |
70 | |||
71 | argv += optind; | ||
69 | if (opt & OPT_p) { | 72 | if (opt & OPT_p) { |
70 | if (argc == optind+1) { /* -p <priority> <pid> */ | 73 | pid_str = *argv++; |
71 | priority = p_opt; | 74 | if (*argv) { /* "-p <priority> <pid> [...]" */ |
72 | p_opt = argv[optind]; | 75 | priority = pid_str; |
76 | pid_str = *argv; | ||
73 | } | 77 | } |
74 | argv += optind; /* me -p <arg> */ | 78 | /* else "-p <pid>", and *argv == NULL */ |
75 | pid = xatoul_range(p_opt, 1, ULONG_MAX); /* -p <pid> */ | 79 | pid = xatoul_range(pid_str, 1, ((unsigned)(pid_t)ULONG_MAX) >> 1); |
76 | } else { | 80 | } else { |
77 | argv += optind; /* me -p <arg> */ | 81 | priority = *argv++; |
78 | priority = *argv; | 82 | if (!*argv) |
79 | } | 83 | bb_show_usage(); |
80 | if (priority) { | ||
81 | /* from the manpage of sched_getscheduler: | ||
82 | [...] sched_priority can have a value | ||
83 | in the range 0 to 99. | ||
84 | [...] SCHED_OTHER or SCHED_BATCH must be assigned | ||
85 | the static priority 0. [...] SCHED_FIFO or | ||
86 | SCHED_RR can have a static priority in the range 1 to 99. | ||
87 | */ | ||
88 | prio = xstrtol_range(priority, 0, policy == SCHED_OTHER | ||
89 | ? 0 : 1, 99); | ||
90 | } | 84 | } |
91 | 85 | ||
86 | current_new = "current\0new"; | ||
92 | if (opt & OPT_p) { | 87 | if (opt & OPT_p) { |
93 | int pol = 0; | 88 | int pol; |
94 | print_rt_info: | 89 | print_rt_info: |
95 | pol = sched_getscheduler(pid); | 90 | pol = sched_getscheduler(pid); |
96 | if (pol < 0) | 91 | if (pol < 0) |
97 | bb_perror_msg_and_die("failed to %cet pid %d's policy", 'g', pid); | 92 | bb_perror_msg_and_die("can't %cet pid %d's policy", 'g', pid); |
98 | printf("pid %d's %s scheduling policy: %s\n", | 93 | printf("pid %d's %s scheduling policy: %s\n", |
99 | pid, state, policies[pol].name); | 94 | pid, current_new, policies[pol].name); |
100 | if (sched_getparam(pid, &sp)) | 95 | if (sched_getparam(pid, &sp)) |
101 | bb_perror_msg_and_die("failed to get pid %d's attributes", pid); | 96 | bb_perror_msg_and_die("can't get pid %d's attributes", pid); |
102 | printf("pid %d's %s scheduling priority: %d\n", | 97 | printf("pid %d's %s scheduling priority: %d\n", |
103 | pid, state, sp.sched_priority); | 98 | pid, current_new, sp.sched_priority); |
104 | if (!*argv) /* no new prio given or we did print already, done. */ | 99 | if (!*argv) { |
100 | /* Either it was just "-p <pid>", | ||
101 | * or it was "-p <priority> <pid>" and we came here | ||
102 | * for the second time (see goto below) */ | ||
105 | return EXIT_SUCCESS; | 103 | return EXIT_SUCCESS; |
104 | } | ||
105 | *argv = NULL; | ||
106 | current_new += 8; | ||
106 | } | 107 | } |
107 | 108 | ||
108 | sp.sched_priority = prio; | 109 | /* from the manpage of sched_getscheduler: |
110 | [...] sched_priority can have a value in the range 0 to 99. | ||
111 | [...] SCHED_OTHER or SCHED_BATCH must be assigned static priority 0. | ||
112 | [...] SCHED_FIFO or SCHED_RR can have static priority in 1..99 range. | ||
113 | */ | ||
114 | sp.sched_priority = xstrtou_range(priority, 0, policy != SCHED_OTHER ? 1 : 0, 99); | ||
115 | |||
109 | if (sched_setscheduler(pid, policy, &sp) < 0) | 116 | if (sched_setscheduler(pid, policy, &sp) < 0) |
110 | bb_perror_msg_and_die("failed to %cet pid %d's policy", 's', pid); | 117 | bb_perror_msg_and_die("can't %cet pid %d's policy", 's', pid); |
111 | if (opt & OPT_p) { | 118 | |
112 | state += 8; | 119 | if (!*argv) /* "-p <priority> <pid> [...]" */ |
113 | ++argv; | ||
114 | goto print_rt_info; | 120 | goto print_rt_info; |
115 | } | 121 | |
116 | ++argv; | ||
117 | BB_EXECVP(*argv, argv); | 122 | BB_EXECVP(*argv, argv); |
118 | bb_simple_perror_msg_and_die(*argv); | 123 | bb_simple_perror_msg_and_die(*argv); |
119 | } | 124 | } |
120 | #undef OPT_p | ||
121 | #undef OPT_r | ||
122 | #undef OPT_f | ||
123 | #undef OPT_o | ||
124 | #undef OPT_m | ||