From: Karel Zak Date: Thu, 21 Jul 2011 14:44:55 +0000 (+0200) Subject: ionice: fix -p X-Git-Tag: v2.20-rc1~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ab08ba3e5e6f161b93ff2b3b7d5b18dc7b44510;p=thirdparty%2Futil-linux.git ionice: fix -p $ 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 --- diff --git a/schedutils/ionice.c b/schedutils/ionice.c index f5f53a33a1..a1bf31fd21 100644 --- a/schedutils/ionice.c +++ b/schedutils/ionice.c @@ -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 */