taskset hangs when executed with badly formatted cpuset list, for
example:
$ taskset -c 0--1 true
The current cpuset list parser is pretty weak as based on scanf()
without strings verification ("-1" as input for "%u" returns
unexpected number). It seems faster and better to use strtoul() and
isdigit().
Addresses: https://github.com/karelzak/util-linux/issues/77
Signed-off-by: Karel Zak <kzak@redhat.com>
There is no need for 'else' when 'if' will return. In same go move call of
tolower() to last possible moment in char_to_val(), a lot of time hex values
should hit 0-9 range, and it can be omitted.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
We use the code from include/ and lib/ on many places, so use public
domain if possible or LGPL for code copied from libs.
Signed-off-by: Karel Zak <kzak@redhat.com>
loopdev.c, test_pager, and get_max_number_of_cpus() are linux-specific.
get_linux_version will only work on Linux, let's introduce
system_supports_ext4_ext2() which assumes that mounting ext2 with ext4
is not supported on non-Linux systems.
[kzak@redhat.com: - use #ifdef SYS_sched_getaffinity rather than __linux__]
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
Reduce code duplication and print better error message if an
unsupported cpu number was passed.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
The current cpulist_parse() function ignores extra non-parsable characters at
the end of the to be parsed cpu list string. E.g. it would accept something
like "0bla" and just set bit 0 in the cpu set. Since such a string is invalid
implement stricter parsing that makes sure that everything of the string has
been succesfully parsed.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
If cpulist_parse() gets passed a cpu list with a stride value of 0 it will be
stuck in an endless loop. E.g. the following cpu list will cause an endless
loop: "0-2:0". Fix this by causing a parse error if the stride value is 0.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
The opening and closing braces for two following if statements within
cpulist_parse() are placed in an odd manner.
Just fix this to prevent broken code in the future.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
The comments for cpumask_parse() and cpulist_parse() each describe
the wrong function. Just exchange the comments.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
This is a preparation patch for chcpu. If a cpu should be added to
a cpu_set where the cpu doesn't fit into the cpu_set this got silently
ignored.
Since the cpu-list is user space provided it should be checked if cpus
are specified that are completely out of range of the system.
In order to do that add a parameter which specifies if cpulist_parse()
should fail if it parses a cpu-list with "impossible" cpus.
The current callers have been converted so they behave like before.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
The free() before exit() is not so important, but let's keep the
example code nice and consistent.
Reported-by: Steve Grubb <sgrubb@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Solaris lacks err, errx, warn and warnx. This also means the err.h header
doesn't exist. Removed err.h include from all files, and included err.h from
c.h instead if it exists, otherwise alternatives are provided.
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
The glibc already supports dynamically allocated CPU sets. We don't
have to maintains our private non-compatible implementation.
Signed-off-by: Karel Zak <kzak@redhat.com>