X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;ds=sidebyside;f=miscutils%2Ftaskset.c;h=a0bbf0aa190e320942b42f4b6d5a0a3b4a8048e3;hb=7cfec4b3e06cc1414079c4cea23239730959bf62;hp=bf98ea15d1bf5056fcc9e26bd88d8a781cfa5cc8;hpb=45ecfc2f5cda05dc9a2091ac610af03a8314ca4a;p=oweals%2Fbusybox.git diff --git a/miscutils/taskset.c b/miscutils/taskset.c index bf98ea15d..a0bbf0aa1 100644 --- a/miscutils/taskset.c +++ b/miscutils/taskset.c @@ -1,47 +1,68 @@ /* vi: set sw=4 ts=4: */ /* * taskset - retrieve or set a processes' CPU affinity - * Copyright (c) 2006 Bernhard Fischer + * Copyright (c) 2006 Bernhard Reutner-Fischer * * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ #include -#include /* optind */ #include "libbb.h" #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); + char *ret = NULL; + char *str = xzalloc((CPU_SETSIZE / 4) + 1); /* we will leak it */ for (i = CPU_SETSIZE - 4; i >= 0; i -= 4) { - char val = 0; + int val = 0; int off; for (off = 0; off <= 3; ++off) - if (CPU_ISSET(i+off, mask)) - val |= 1<", * or it was "-p " and we came here @@ -94,8 +115,10 @@ int taskset_main(int argc ATTRIBUTE_UNUSED, char **argv) unsigned i; /* Do not allow zero mask: */ unsigned long long m = xstrtoull_range(aff, 0, 1, ULLONG_MAX); + enum { CNT_BIT = CPU_SETSIZE < sizeof(m)*8 ? CPU_SETSIZE : sizeof(m)*8 }; + CPU_ZERO(&mask); - for (i = 0; i < CPU_SETSIZE; i++) { + for (i = 0; i < CNT_BIT; i++) { unsigned long long bit = (1ULL << i); if (bit & m) CPU_SET(i, &mask);