aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-01-30 22:20:06 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-01-30 22:20:06 +0100
commitd6ace669737571c98977972b7392456f9e5156f6 (patch)
tree35249ea846f91221127235b9f9705db85fbe2bea
parentca659f84b20ae63e0d11d9b1bfa2f9d610e05faa (diff)
downloadbusybox-w32-d6ace669737571c98977972b7392456f9e5156f6.tar.gz
busybox-w32-d6ace669737571c98977972b7392456f9e5156f6.tar.bz2
busybox-w32-d6ace669737571c98977972b7392456f9e5156f6.zip
taskset: simplify code a bit; tweak --help
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/taskset.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/miscutils/taskset.c b/miscutils/taskset.c
index 68b0fa6eb..94a07383a 100644
--- a/miscutils/taskset.c
+++ b/miscutils/taskset.c
@@ -26,7 +26,7 @@
26//kbuild:lib-$(CONFIG_TASKSET) += taskset.o 26//kbuild:lib-$(CONFIG_TASKSET) += taskset.o
27 27
28//usage:#define taskset_trivial_usage 28//usage:#define taskset_trivial_usage
29//usage: "[-p] [HEXMASK] [PID | PROG ARGS]" 29//usage: "[-p] [HEXMASK] PID | PROG ARGS"
30//usage:#define taskset_full_usage "\n\n" 30//usage:#define taskset_full_usage "\n\n"
31//usage: "Set or get CPU affinity\n" 31//usage: "Set or get CPU affinity\n"
32//usage: "\n -p Operate on an existing PID" 32//usage: "\n -p Operate on an existing PID"
@@ -116,7 +116,7 @@ int taskset_main(int argc UNUSED_PARAM, char **argv)
116 pid_t pid = 0; 116 pid_t pid = 0;
117 unsigned opt_p; 117 unsigned opt_p;
118 const char *current_new; 118 const char *current_new;
119 char *aff = aff; /* for compiler */ 119 char *aff;
120 120
121 /* NB: we mimic util-linux's taskset: -p does not take 121 /* NB: we mimic util-linux's taskset: -p does not take
122 * an argument, i.e., "-pN" is NOT valid, only "-p N"! 122 * an argument, i.e., "-pN" is NOT valid, only "-p N"!
@@ -127,29 +127,28 @@ int taskset_main(int argc UNUSED_PARAM, char **argv)
127 opt_p = getopt32(argv, "+p"); 127 opt_p = getopt32(argv, "+p");
128 argv += optind; 128 argv += optind;
129 129
130 aff = *argv++;
130 if (opt_p) { 131 if (opt_p) {
131 char *pid_str = *argv++; 132 char *pid_str = aff;
132 if (*argv) { /* "-p <aff> <pid> ...rest.is.ignored..." */ 133 if (*argv) { /* "-p <aff> <pid> ...rest.is.ignored..." */
133 aff = pid_str;
134 pid_str = *argv; /* NB: *argv != NULL in this case */ 134 pid_str = *argv; /* NB: *argv != NULL in this case */
135 } 135 }
136 /* else it was just "-p <pid>", and *argv == NULL */ 136 /* else it was just "-p <pid>", and *argv == NULL */
137 pid = xatoul_range(pid_str, 1, ((unsigned)(pid_t)ULONG_MAX) >> 1); 137 pid = xatoul_range(pid_str, 1, ((unsigned)(pid_t)ULONG_MAX) >> 1);
138 } else { 138 } else {
139 aff = *argv++; /* <aff> <cmd...> */ 139 /* <aff> <cmd...> */
140 if (!*argv) 140 if (!*argv)
141 bb_show_usage(); 141 bb_show_usage();
142 } 142 }
143 143
144 mask_size_in_bytes = SZOF_UL; 144 mask_size_in_bytes = SZOF_UL;
145 mask = NULL;
146 current_new = "current"; 145 current_new = "current";
147 print_aff: 146 print_aff:
148 mask = get_aff(pid, &mask_size_in_bytes); 147 mask = get_aff(pid, &mask_size_in_bytes);
149 if (opt_p) { 148 if (opt_p) {
150 printf("pid %d's %s affinity mask: "TASKSET_PRINTF_MASK"\n", 149 printf("pid %d's %s affinity mask: "TASKSET_PRINTF_MASK"\n",
151 pid, current_new, from_mask(mask, mask_size_in_bytes)); 150 pid, current_new, from_mask(mask, mask_size_in_bytes));
152 if (!*argv) { 151 if (*argv == NULL) {
153 /* Either it was just "-p <pid>", 152 /* Either it was just "-p <pid>",
154 * or it was "-p <aff> <pid>" and we came here 153 * or it was "-p <aff> <pid>" and we came here
155 * for the second time (see goto below) */ 154 * for the second time (see goto below) */
@@ -166,8 +165,7 @@ int taskset_main(int argc UNUSED_PARAM, char **argv)
166 aff += 2; 165 aff += 2;
167 166
168 if (!ENABLE_FEATURE_TASKSET_FANCY) { 167 if (!ENABLE_FEATURE_TASKSET_FANCY) {
169 /* Do not allow zero mask: */ 168 mask[0] = xstrtoul(aff, 16);
170 mask[0] = xstrtoul_range(aff, 16, 1, ULONG_MAX);
171 } else { 169 } else {
172 unsigned i; 170 unsigned i;
173 char *last_char; 171 char *last_char;
@@ -201,8 +199,8 @@ int taskset_main(int argc UNUSED_PARAM, char **argv)
201 /* else: 199 /* else:
202 * We can error out here, but we don't. 200 * We can error out here, but we don't.
203 * For one, kernel itself ignores bits in mask[] 201 * For one, kernel itself ignores bits in mask[]
204 * which do not map to any CPUs. 202 * which do not map to any CPUs:
205 * If mask has one 32-bit long, 203 * if mask[] has one 32-bit long element,
206 * but you have only 8 CPUs, all bits beyond first 8 204 * but you have only 8 CPUs, all bits beyond first 8
207 * are ignored, silently. 205 * are ignored, silently.
208 * No point in making bits past 31th to be errors. 206 * No point in making bits past 31th to be errors.