Previously, `toybox taskset` used the high bits of an overlong mask, but util-linux used the low bits. Use the low bits.
% ./toybox taskset $( printf %99999s | tr ' ' 0 )f echo ok taskset: failed to set pid 1580999's affinity: Invalid argument % taskset $( printf %99999s | tr ' ' 0 )f echo ok ok Reported in http://lists.landley.net/pipermail/toybox-landley.net/2025-June/030734.html diff --git a/tests/taskset.test b/tests/taskset.test index acd2869fbc..bfb52e282a 100755 --- a/tests/taskset.test +++ b/tests/taskset.test @@ -35,5 +35,7 @@ testing "long mask doesn't segfault" \ 'taskset $(printf %99999s | tr \ f) echo; echo $?' '\n0\n' '' '' +testing "long mask uses low bits" \ + 'taskset $(printf %99999s | tr \ 0)1 echo; echo $?' '\n0\n' '' '' testing "taskset error checking" \ 'taskset 0 echo nope 2>/dev/null; echo $?' '1\n' '' '' diff --git a/toys/other/taskset.c b/toys/other/taskset.c index cc33d94e3b..458fbeffef 100644 --- a/toys/other/taskset.c +++ b/toys/other/taskset.c @@ -66,10 +66,11 @@ if (i || toys.optc < 2) return; - // Convert hex strong to mask[] bits + // Convert hex string to mask[] bits memset(toybuf, 0, sizeof(toybuf)); - k = minof(strlen(s = *toys.optargs), 2*sizeof(toybuf)); + k = strlen(s = *toys.optargs); s += k; + k = minof(k, 2*sizeof(toybuf)); for (j = 0; j<k; j++) { unsigned long digit = *(--s) - '0';
_______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net