]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
ionice: fix -p
authorKarel Zak <kzak@redhat.com>
Thu, 21 Jul 2011 14:44:55 +0000 (16:44 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 21 Jul 2011 15:02:52 +0000 (17:02 +0200)
 $ ionice 123
 none: prio 4
 none: prio 4

It calls ioprio_get(0x1, 0) and ioprio_get(0x1, 123), because the
code does not check it the "-p" options was specified.

The proper command line syntax is:

  $ ionice -p 123

and the ioprio_get() should be called only once.

Signed-off-by: Karel Zak <kzak@redhat.com>
schedutils/ionice.c

index f5f53a33a17c6fe1c490b6e468ab1f08efddbfc3..a1bf31fd2162aef55a85540a3116eb07f4cc5589 100644 (file)
@@ -152,6 +152,11 @@ int main(int argc, char *argv[])
                }
        }
 
+       if (!set && !pid && optind == argc)
+               errx(EXIT_FAILURE, _("PID or COMMAND not specified"));
+       if (!set && !pid)
+               errx(EXIT_FAILURE, _("scheduling for the COMMAND not specified"));
+
        switch (ioclass) {
                case IOPRIO_CLASS_NONE:
                        if (set & 1)
@@ -185,8 +190,7 @@ int main(int argc, char *argv[])
                                pid = strtol_or_err(argv[optind], _("failed to parse pid"));
                                ioprio_setpid(pid, ioclass, data);
                        }
-               }
-               else if (argv[optind]) {
+               } else if (argv[optind]) {
                        ioprio_setpid(0, ioclass, data);
                        execvp(argv[optind], &argv[optind]);
                        /* execvp should never return */