]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
ionice: make -t more tolerant
authorKarel Zak <kzak@redhat.com>
Fri, 22 Jul 2011 10:37:57 +0000 (12:37 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 22 Jul 2011 10:55:01 +0000 (12:55 +0200)
* replace errx() with warnx() for unknown -c class

  The right place to check I/O scheduler features is in kernel. We should
  not try to be more smart than kernel.

* make the code ready (robust) for unknown sched.classes

* fix -t behavior

old version:
  $ ionice -c 4 -t bash
  ionice: bad prio class 4

new version:
  $ ionice -c 4 -t bash

Reported-by: Voelker, Bernhard" <bernhard.voelker@siemens-enterprise.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
schedutils/ionice.c

index 26dc2d3a822757b2ae41786f0b93927994669ba1..75f372e0787f72112ef1b3450060ac6a74bc2829 100644 (file)
@@ -75,12 +75,16 @@ static void ioprio_print(int pid)
                err(EXIT_FAILURE, _("ioprio_get failed"));
        else {
                int ioclass = IOPRIO_PRIO_CLASS(ioprio);
+               const char *name = _("unknown");
+
+               if (ioclass < ARRAY_SIZE(to_prio))
+                       name = to_prio[ioclass];
 
                if (ioclass != IOPRIO_CLASS_IDLE)
-                       printf("%s: prio %lu\n", to_prio[ioclass],
+                       printf("%s: prio %lu\n", name,
                                        IOPRIO_PRIO_DATA(ioprio));
                else
-                       printf("%s\n", to_prio[ioclass]);
+                       printf("%s\n", name);
        }
 }
 
@@ -173,7 +177,7 @@ int main(int argc, char **argv)
 
        switch (ioclass) {
                case IOPRIO_CLASS_NONE:
-                       if (set & 1)
+                       if ((set & 1) && !tolerant)
                                warnx(_("ignoring given class data for none class"));
                        data = 0;
                        break;
@@ -181,12 +185,14 @@ int main(int argc, char **argv)
                case IOPRIO_CLASS_BE:
                        break;
                case IOPRIO_CLASS_IDLE:
-                       if (set & 1)
+                       if ((set & 1) && !tolerant)
                                warnx(_("ignoring given class data for idle class"));
                        data = 7;
                        break;
                default:
-                       errx(EXIT_FAILURE, _("bad prio class %d"), ioclass);
+                       if (!tolerant)
+                               warnx(_("unknown prio class %d"), ioclass);
+                       break;
        }
 
        if (!set && !pid && optind == argc)