Commit Graph

27 Commits

Author SHA1 Message Date
Karel Zak 65bcbf105b taskset: fix cpuset list parser
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>
2019-03-20 13:12:25 +01:00
Sami Kerola 35e82b2926 lib: simplify cpuset if clauses that return
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>
2017-06-14 12:22:54 +02:00
Sami Kerola 4783f2005d
lib/cpuset: stop changing variable that is not read
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-04-01 09:24:37 +01:00
Sami Kerola 71f08e9706
tests: do not use plain 0 as NULL [smatch scan]
Likewise commit 8791804065.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-17 21:22:26 +00:00
Karel Zak e8f7acb0d3 lib: use unique ifdefs for tests
Let's use unique TEST_PROGRAM_<NAME> ifdefs to make build system more
robust.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-04 11:44:37 +01:00
Yuriy M. Kaminskiy 06fa581748 misc: safer (and uniform) handling of return value
When `rc` is `INT_MAX`, `rc + 1` result in signed integer overflow.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-03-07 15:11:06 +01:00
Boris Egorov e3ca1312a2 sys-utils/disk-utils/lib: fix printf format types [cppcheck]
Fix 'invalidPrintfArgType' cppcheck warnings

Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-25 12:08:45 +02:00
Sami Kerola 41cd150303 tests: fix memory leak [AddressSanitizer]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-11-18 12:55:50 +01:00
Karel Zak 0f23ee0c85 include: cleanup copyright headers
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>
2013-01-08 15:10:17 +01:00
Samuel Thibault 4797b1e592 Fix non-Linux build
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>
2012-08-13 15:14:13 +02:00
Karel Zak 4e9b3bfda2 lib,cpuset: fix compiler warning [-Wuninitialized]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-10 00:02:00 +02:00
Heiko Carstens 59fb133a02 chcpu,cpuset: reduce code duplication for cpu list parsing
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>
2011-09-10 00:00:35 +02:00
Heiko Carstens f27ce0711c lib,cpuset: enforce stricter parsing of cpu lists
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>
2011-09-10 00:00:33 +02:00
Heiko Carstens 72232a267a lib,cpuset: fix stride handling in cpulist_parse()
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>
2011-09-10 00:00:24 +02:00
Heiko Carstens 289127f52d lib,cpuset: fix odd placed braces in cpulist_parse()
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>
2011-09-10 00:00:15 +02:00
Heiko Carstens 68845fed01 lib,cpuset: fix comments for cpu mask/list functions
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>
2011-09-10 00:00:14 +02:00
Heiko Carstens b16f615afb cpuset: add option to allow cpulist_parse() to fail
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>
2011-08-15 07:52:44 +02:00
Karel Zak 8a929ed7c0 lib: [cpuset.c] fix compiler warnings [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 12:24:22 +02:00
Karel Zak 6c7d5ae9a2 move struct option to .rodata
It does not make sense to have writable large arrays of "struct
option" on the stack.

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-03 15:00:30 +01:00
Karel Zak 9da2972c15 tests: [cpuset] call free() for range
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>
2011-02-17 11:26:36 +01:00
Fabian Groffen eb76ca98b0 build-sys: provide alternatives for err, errx, warn and warnx
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>
2011-02-14 17:45:24 +01:00
Karel Zak 218f9d3d66 remove duplicate includes
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-04 22:36:09 +01:00
Karel Zak bae91ecf07 taskset: move NR_CPUS determination to lib/cpuset.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-01 11:11:26 +02:00
Karel Zak ee32c514b5 lib: add fallback for libc (uClibc) without CPU_ALLOC
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-01 11:09:23 +02:00
Karel Zak ff5a6d2067 taskset: use libc based cpu_set_t
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>
2010-06-01 11:06:50 +02:00
Karel Zak 125b6a9191 tests: add cpuset regression test
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-01 11:06:49 +02:00
Karel Zak efcb71f8ff taskset: move bitmap routines to lib/cpuset.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-06-01 11:04:44 +02:00