]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cpuset: add option to allow cpulist_parse() to fail
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Mon, 15 Aug 2011 05:52:44 +0000 (07:52 +0200)
committerHeiko Carstens <heiko.carstens@de.ibm.com>
Mon, 15 Aug 2011 05:52:44 +0000 (07:52 +0200)
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>
include/cpuset.h
lib/cpuset.c
schedutils/taskset.c
sys-utils/lscpu.c

index 93646605589844edbbdbd986269b5e46999d50bf..f65c0cad7ae0f3ce83f8b6a5f4a687b1a6e3f20b 100644 (file)
@@ -67,7 +67,7 @@ extern cpu_set_t *cpuset_alloc(int ncpus, size_t *setsize, size_t *nbits);
 extern void cpuset_free(cpu_set_t *set);
 
 extern char *cpulist_create(char *str, size_t len, cpu_set_t *set, size_t setsize);
-extern int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize);
+extern int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize, int fail);
 
 extern char *cpumask_create(char *str, size_t len, cpu_set_t *set, size_t setsize);
 extern int cpumask_parse(const char *str, cpu_set_t *set, size_t setsize);
index 8aa296a55e6907f52d5a342d69df5ac3fee58b35..dd31f5231ab58870d8624b3443c9f9887a4e1b6e 100644 (file)
@@ -264,8 +264,9 @@ int cpumask_parse(const char *str, cpu_set_t *set, size_t setsize)
 /*
  * Parses string with CPUs mask.
  */
-int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize)
+int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize, int fail)
 {
+       size_t max = cpuset_nbits(setsize);
        const char *p, *q;
        q = str;
 
@@ -297,6 +298,8 @@ int cpulist_parse(const char *str, cpu_set_t *set, size_t setsize)
                if (!(a <= b))
                        return 1;
                while (a <= b) {
+                       if (fail && (a >= max))
+                               return 1;
                        CPU_SET_S(a, setsize, set);
                        a += s;
                }
@@ -359,7 +362,7 @@ int main(int argc, char *argv[])
        if (mask)
                rc = cpumask_parse(mask, set, setsize);
        else
-               rc = cpulist_parse(range, set, setsize);
+               rc = cpulist_parse(range, set, setsize, 0);
 
        if (rc)
                errx(EXIT_FAILURE, "failed to parse string: %s", mask ? : range);
index 1457c651dcb040516687beb88f99659000804ceb..085675d7a8e8e0dbb7233feba18ef2fb87c6b5ab 100644 (file)
@@ -208,7 +208,7 @@ int main(int argc, char **argv)
                ts.get_only = 1;
 
        else if (ts.use_list) {
-               if (cpulist_parse(argv[optind], new_set, new_setsize))
+               if (cpulist_parse(argv[optind], new_set, new_setsize, 0))
                        errx(EXIT_FAILURE, _("failed to parse CPU list: %s"),
                             argv[optind]);
        } else if (cpumask_parse(argv[optind], new_set, new_setsize)) {
index 50daf3c4c587b46b4d998619cb13820deef965c0..12779f1b190e5a73eb1fad767a2c4b4ebe08eb74 100644 (file)
@@ -304,7 +304,7 @@ path_cpuparse(int islist, const char *path, va_list ap)
                err(EXIT_FAILURE, _("failed to callocate cpu set"));
 
        if (islist) {
-               if (cpulist_parse(buf, set, setsize))
+               if (cpulist_parse(buf, set, setsize, 0))
                        errx(EXIT_FAILURE, _("failed to parse CPU list %s"), buf);
        } else {
                if (cpumask_parse(buf, set, setsize))