]> err.no Git - util-linux/commitdiff
ionice: clean up error handling
authorMatthias Koenig <mkoenig@suse.de>
Mon, 27 Aug 2007 14:49:19 +0000 (16:49 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 27 Aug 2007 21:58:05 +0000 (23:58 +0200)
Print error in case execvp fails and use exit macros.

Based on patch by Bernhard Voelker <mail@bernhard-voelker.de>

Signed-off-by: Matthias Koenig <mkoenig@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
schedutils/ionice.c

index 2d23dd0e77c0b3c3f5c52494ee644afacfcec74e..9eb13877b08def5f7c4226e0761674a033cd151f 100644 (file)
@@ -107,7 +107,7 @@ int main(int argc, char *argv[])
                case 'h':
                default:
                        usage();
-                       exit(0);
+                       exit(EXIT_SUCCESS);
                }
        }
 
@@ -125,7 +125,7 @@ int main(int argc, char *argv[])
                        break;
                default:
                        printf("bad prio class %d\n", ioprio_class);
-                       return 1;
+                       exit(EXIT_FAILURE);
        }
 
        if (!set) {
@@ -134,9 +134,10 @@ int main(int argc, char *argv[])
 
                ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid);
 
-               if (ioprio == -1)
+               if (ioprio == -1) {
                        perror("ioprio_get");
-               else {
+                       exit(EXIT_FAILURE);
+               } else {
                        ioprio_class = ioprio >> IOPRIO_CLASS_SHIFT;
                        if (ioprio_class != IOPRIO_CLASS_IDLE) {
                                ioprio = ioprio & 0xff;
@@ -147,12 +148,16 @@ int main(int argc, char *argv[])
        } else {
                if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << IOPRIO_CLASS_SHIFT) == -1) {
                        perror("ioprio_set");
-                       return 1;
+                       exit(EXIT_FAILURE);
                }
 
-               if (argv[optind])
+               if (argv[optind]) {
                        execvp(argv[optind], &argv[optind]);
+                       /* execvp should never return */
+                       perror("execvp");
+                       exit(EXIT_FAILURE);
+               }
        }
 
-       return 0;
+       exit(EXIT_SUCCESS);
 }