aboutsummaryrefslogtreecommitdiff
path: root/miscutils/taskset.c
diff options
context:
space:
mode:
authorGravatar Denis Vlasenko <vda.linux@googlemail.com>2006-12-30 17:57:03 +0000
committerGravatar Denis Vlasenko <vda.linux@googlemail.com>2006-12-30 17:57:03 +0000
commit3bba545a54addf59b63a003e7ada03fd8b29b5ba (patch)
tree948ce196f871abcf9410ca1521a3d2a5af6a3082 /miscutils/taskset.c
parentb5a122b6f9643fb052d31390e435397960289154 (diff)
downloadbusybox-3bba545a54addf59b63a003e7ada03fd8b29b5ba.tar.gz
busybox-3bba545a54addf59b63a003e7ada03fd8b29b5ba.tar.bz2
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.c32
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 @@
#include "busybox.h"
#include <sched.h>
-#include <unistd.h>
#include <getopt.h> /* optind */
#if ENABLE_FEATURE_TASKSET_FANCY
#define TASKSET_PRINTF_MASK "%s"
#define from_cpuset(x) __from_cpuset(&x)
/* craft a string from the mask */
-static char *__from_cpuset(cpu_set_t *mask) {
+static char *__from_cpuset(cpu_set_t *mask)
+{
int i;
char *ret = 0, *str = xzalloc(9);
@@ -34,22 +34,24 @@ static char *__from_cpuset(cpu_set_t *mask) {
}
#else
#define TASKSET_PRINTF_MASK "%x"
-#define from_cpuset(mask) mask
+/* (void*) cast is for battling gcc: */
+/* "dereferencing type-punned pointer will break strict-aliasing rules" */
+#define from_cpuset(mask) (*(unsigned*)(void*)&(mask))
#endif
-#define TASKSET_OPT_p (1)
+#define OPT_p 1
int taskset_main(int argc, char** argv)
{
cpu_set_t mask, new_mask;
pid_t pid = 0;
- unsigned long ul;
+ unsigned opt;
const char *state = "current\0new";
char *p_opt = NULL, *aff = NULL;
- ul = getopt32(argc, argv, "+p:", &p_opt);
+ opt = getopt32(argc, argv, "+p:", &p_opt);
- if (ul & TASKSET_OPT_p) {
+ if (opt & OPT_p) {
if (argc == optind+1) { /* -p <aff> <pid> */
aff = p_opt;
p_opt = argv[optind];
@@ -70,19 +72,19 @@ int taskset_main(int argc, char** argv)
}
}
- if (ul & TASKSET_OPT_p) {
-print_aff:
- if (sched_getaffinity(pid, sizeof (mask), &mask) < 0)
- bb_perror_msg_and_die("Failed to %cet pid %d's affinity", 'g', pid);
+ if (opt & OPT_p) {
+ print_aff:
+ if (sched_getaffinity(pid, sizeof(mask), &mask) < 0)
+ bb_perror_msg_and_die("failed to %cet pid %d's affinity", 'g', pid);
printf("pid %d's %s affinity mask: "TASKSET_PRINTF_MASK"\n",
pid, state, from_cpuset(mask));
if (!*argv) /* no new affinity given or we did print already, done. */
return EXIT_SUCCESS;
}
- if (sched_setaffinity(pid, sizeof (new_mask), &new_mask))
- bb_perror_msg_and_die("Failed to %cet pid %d's affinity", 's', pid);
- if (ul & TASKSET_OPT_p) {
+ if (sched_setaffinity(pid, sizeof(new_mask), &new_mask))
+ bb_perror_msg_and_die("failed to %cet pid %d's affinity", 's', pid);
+ if (opt & OPT_p) {
state += 8;
++argv;
goto print_aff;
@@ -91,6 +93,6 @@ print_aff:
execvp(*argv, argv);
bb_perror_msg_and_die("%s", *argv);
}
-#undef TASKSET_OPT_p
+#undef OPT_p
#undef TASKSET_PRINTF_MASK
#undef from_cpuset