]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
ionice: improve command line interpretation
authorKarel Zak <kzak@redhat.com>
Fri, 22 Jul 2011 09:15:28 +0000 (11:15 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 22 Jul 2011 09:24:05 +0000 (11:24 +0200)
 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 <kzak@redhat.com>
schedutils/ionice.1
schedutils/ionice.c

index 1a01b3b8707430e132e079f66680ec7c37a1883d..4f9cd5041eee5f6cc5e2f85d7877c883604969b1 100644 (file)
@@ -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
index 7c6897f08bb0b95b5e0a327151595bbafd804090..f1db216ef10b2598da2139c1a0f9e5d62fa678d3 100644 (file)
@@ -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;
 }