From: Karel Zak Date: Fri, 22 Jul 2011 09:15:28 +0000 (+0200) Subject: ionice: improve command line interpretation X-Git-Tag: v2.20-rc1~49 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fcc2b2da4ca5efcc82d31b11cdb9b16f90cd31c3;p=thirdparty%2Futil-linux.git ionice: improve command line interpretation ionice : print the current I/O prio. ionice COMMAND : exec command with default (best-effort) class ionice -p PID [...] : return info about the PID(s) ionice -c CLASS COMMAND : exec command with the class ionice -c CLASS -p PID [...] : modify PID(s) class This should be backwardly compatible and also compatible with nice(1) from coreutils. Signed-off-by: Karel Zak --- diff --git a/schedutils/ionice.1 b/schedutils/ionice.1 index 1a01b3b870..4f9cd5041e 100644 --- a/schedutils/ionice.1 +++ b/schedutils/ionice.1 @@ -25,6 +25,11 @@ This program sets or gets the io scheduling class and priority for a program. If no arguments or just \fB\-p\fR is given, \fBionice\fR will query the current io scheduling class and priority for that process. +If no class is given than +.I COMMAND +will be executed with "best effort" scheduling class. The default +priority argument is 4. + As of this writing, a process can be in one of three scheduling classes: .IP "\fBIdle\fP" A program running with idle io priority will only get disk time when no other diff --git a/schedutils/ionice.c b/schedutils/ionice.c index 7c6897f08b..f1db216ef1 100644 --- a/schedutils/ionice.c +++ b/schedutils/ionice.c @@ -151,11 +151,6 @@ int main(int argc, char **argv) usage(stderr); } - 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) @@ -174,28 +169,42 @@ int main(int argc, char **argv) errx(EXIT_FAILURE, _("bad prio class %d"), ioclass); } - if (!set) { + if (!set && !pid && optind == argc) + /* + * ionice without options, print the current ioprio + */ + ioprio_print(0); + + else if (!set && pid) { + /* + * ionice -p PID [PID ...] + */ ioprio_print(pid); for(; argv[optind]; ++optind) { pid = strtol_or_err(argv[optind], _("failed to parse pid")); ioprio_print(pid); } - } else { - if (pid) { - ioprio_setpid(pid, ioclass, data); + } else if (set && pid) { + /* + * ionice -c CLASS -p PID [PID ...] + */ + ioprio_setpid(pid, ioclass, data); - for(; argv[optind]; ++optind) { - pid = strtol_or_err(argv[optind], _("failed to parse pid")); - ioprio_setpid(pid, ioclass, data); - } - } else if (argv[optind]) { - ioprio_setpid(0, ioclass, data); - execvp(argv[optind], &argv[optind]); - /* execvp should never return */ - err(EXIT_FAILURE, _("executing %s failed"), argv[optind]); + for(; argv[optind]; ++optind) { + pid = strtol_or_err(argv[optind], _("failed to parse pid")); + ioprio_setpid(pid, ioclass, data); } - } + } else if (argv[optind]) { + /* + * ionice [-c CLASS] COMMAND + */ + ioprio_setpid(0, ioclass, data); + execvp(argv[optind], &argv[optind]); + err(EXIT_FAILURE, _("executing %s failed"), argv[optind]); + } else + usage(stderr); + return EXIT_SUCCESS; }