diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-30 17:57:03 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-30 17:57:03 +0000 |
commit | 3bba545a54addf59b63a003e7ada03fd8b29b5ba (patch) | |
tree | 948ce196f871abcf9410ca1521a3d2a5af6a3082 /miscutils/taskset.c | |
parent | b5a122b6f9643fb052d31390e435397960289154 (diff) | |
download | busybox-w32-3bba545a54addf59b63a003e7ada03fd8b29b5ba.tar.gz busybox-w32-3bba545a54addf59b63a003e7ada03fd8b29b5ba.tar.bz2 busybox-w32-3bba545a54addf59b63a003e7ada03fd8b29b5ba.zip |
done a dozen of randconfig test. guess what? ALL failed...
these are resulting fixes
Diffstat (limited to 'miscutils/taskset.c')
-rw-r--r-- | miscutils/taskset.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/miscutils/taskset.c b/miscutils/taskset.c index 4496aa5b4..a4d41ac9c 100644 --- a/miscutils/taskset.c +++ b/miscutils/taskset.c | |||
@@ -8,14 +8,14 @@ | |||
8 | 8 | ||
9 | #include "busybox.h" | 9 | #include "busybox.h" |
10 | #include <sched.h> | 10 | #include <sched.h> |
11 | #include <unistd.h> | ||
12 | #include <getopt.h> /* optind */ | 11 | #include <getopt.h> /* optind */ |
13 | 12 | ||
14 | #if ENABLE_FEATURE_TASKSET_FANCY | 13 | #if ENABLE_FEATURE_TASKSET_FANCY |
15 | #define TASKSET_PRINTF_MASK "%s" | 14 | #define TASKSET_PRINTF_MASK "%s" |
16 | #define from_cpuset(x) __from_cpuset(&x) | 15 | #define from_cpuset(x) __from_cpuset(&x) |
17 | /* craft a string from the mask */ | 16 | /* craft a string from the mask */ |
18 | static char *__from_cpuset(cpu_set_t *mask) { | 17 | static char *__from_cpuset(cpu_set_t *mask) |
18 | { | ||
19 | int i; | 19 | int i; |
20 | char *ret = 0, *str = xzalloc(9); | 20 | char *ret = 0, *str = xzalloc(9); |
21 | 21 | ||
@@ -34,22 +34,24 @@ static char *__from_cpuset(cpu_set_t *mask) { | |||
34 | } | 34 | } |
35 | #else | 35 | #else |
36 | #define TASKSET_PRINTF_MASK "%x" | 36 | #define TASKSET_PRINTF_MASK "%x" |
37 | #define from_cpuset(mask) mask | 37 | /* (void*) cast is for battling gcc: */ |
38 | /* "dereferencing type-punned pointer will break strict-aliasing rules" */ | ||
39 | #define from_cpuset(mask) (*(unsigned*)(void*)&(mask)) | ||
38 | #endif | 40 | #endif |
39 | 41 | ||
40 | #define TASKSET_OPT_p (1) | 42 | #define OPT_p 1 |
41 | 43 | ||
42 | int taskset_main(int argc, char** argv) | 44 | int taskset_main(int argc, char** argv) |
43 | { | 45 | { |
44 | cpu_set_t mask, new_mask; | 46 | cpu_set_t mask, new_mask; |
45 | pid_t pid = 0; | 47 | pid_t pid = 0; |
46 | unsigned long ul; | 48 | unsigned opt; |
47 | const char *state = "current\0new"; | 49 | const char *state = "current\0new"; |
48 | char *p_opt = NULL, *aff = NULL; | 50 | char *p_opt = NULL, *aff = NULL; |
49 | 51 | ||
50 | ul = getopt32(argc, argv, "+p:", &p_opt); | 52 | opt = getopt32(argc, argv, "+p:", &p_opt); |
51 | 53 | ||
52 | if (ul & TASKSET_OPT_p) { | 54 | if (opt & OPT_p) { |
53 | if (argc == optind+1) { /* -p <aff> <pid> */ | 55 | if (argc == optind+1) { /* -p <aff> <pid> */ |
54 | aff = p_opt; | 56 | aff = p_opt; |
55 | p_opt = argv[optind]; | 57 | p_opt = argv[optind]; |
@@ -70,19 +72,19 @@ int taskset_main(int argc, char** argv) | |||
70 | } | 72 | } |
71 | } | 73 | } |
72 | 74 | ||
73 | if (ul & TASKSET_OPT_p) { | 75 | if (opt & OPT_p) { |
74 | print_aff: | 76 | print_aff: |
75 | if (sched_getaffinity(pid, sizeof (mask), &mask) < 0) | 77 | if (sched_getaffinity(pid, sizeof(mask), &mask) < 0) |
76 | bb_perror_msg_and_die("Failed to %cet pid %d's affinity", 'g', pid); | 78 | bb_perror_msg_and_die("failed to %cet pid %d's affinity", 'g', pid); |
77 | printf("pid %d's %s affinity mask: "TASKSET_PRINTF_MASK"\n", | 79 | printf("pid %d's %s affinity mask: "TASKSET_PRINTF_MASK"\n", |
78 | pid, state, from_cpuset(mask)); | 80 | pid, state, from_cpuset(mask)); |
79 | if (!*argv) /* no new affinity given or we did print already, done. */ | 81 | if (!*argv) /* no new affinity given or we did print already, done. */ |
80 | return EXIT_SUCCESS; | 82 | return EXIT_SUCCESS; |
81 | } | 83 | } |
82 | 84 | ||
83 | if (sched_setaffinity(pid, sizeof (new_mask), &new_mask)) | 85 | if (sched_setaffinity(pid, sizeof(new_mask), &new_mask)) |
84 | bb_perror_msg_and_die("Failed to %cet pid %d's affinity", 's', pid); | 86 | bb_perror_msg_and_die("failed to %cet pid %d's affinity", 's', pid); |
85 | if (ul & TASKSET_OPT_p) { | 87 | if (opt & OPT_p) { |
86 | state += 8; | 88 | state += 8; |
87 | ++argv; | 89 | ++argv; |
88 | goto print_aff; | 90 | goto print_aff; |
@@ -91,6 +93,6 @@ print_aff: | |||
91 | execvp(*argv, argv); | 93 | execvp(*argv, argv); |
92 | bb_perror_msg_and_die("%s", *argv); | 94 | bb_perror_msg_and_die("%s", *argv); |
93 | } | 95 | } |
94 | #undef TASKSET_OPT_p | 96 | #undef OPT_p |
95 | #undef TASKSET_PRINTF_MASK | 97 | #undef TASKSET_PRINTF_MASK |
96 | #undef from_cpuset | 98 | #undef from_cpuset |