fsck: fix incorrect handling of child exit
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 24 May 2018 13:26:28 +0000 (15:26 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 24 May 2018 13:29:15 +0000 (15:29 +0200)
In commit

  c4fb8c6a - fsck: do not use statics

not only statics were changed but also a couple of
statics-unrelated changes were made.

This included the handling of the child termination status
as follows:

    - if (WIFEXITED(status))
    -   status = WEXITSTATUS(status);
    - else if (WIFSIGNALED(status)) {
    + status = WEXITSTATUS(status);
    + if (WIFSIGNALED(status)) {

This is wrong, should have used a different variable to hold exit code.

Reported by Niklas Hambüchen <mail@nh2.me>.

function                                             old     new   delta
wait_one                                             294     282     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
e2fsprogs/fsck.c

index 1c285bb9233566de124b60743b62b0d4cc85e1b1..f5aa3dbe47b3aad4d45c24eb402e2f18a3f7c30d 100644 (file)
@@ -414,7 +414,7 @@ static void kill_all_if_got_signal(void)
 static int wait_one(int flags)
 {
        int status;
-       int sig;
+       int exitcode;
        struct fsck_instance *inst, *prev;
        pid_t pid;
 
@@ -448,15 +448,16 @@ static int wait_one(int flags)
        }
  child_died:
 
-       status = WEXITSTATUS(status);
+       exitcode = WEXITSTATUS(status);
        if (WIFSIGNALED(status)) {
+               unsigned sig;
                sig = WTERMSIG(status);
-               status = EXIT_UNCORRECTED;
+               exitcode = EXIT_UNCORRECTED;
                if (sig != SIGINT) {
                        printf("Warning: %s %s terminated "
-                               "by signal %d\n",
+                               "by signal %u\n",
                                inst->prog, inst->device, sig);
-                       status = EXIT_ERROR;
+                       exitcode = EXIT_ERROR;
                }
        }
 
@@ -492,12 +493,12 @@ static int wait_one(int flags)
        else
                G.instance_list = inst->next;
        if (G.verbose > 1)
-               printf("Finished with %s (exit status %d)\n",
-                       inst->device, status);
+               printf("Finished with %s (exit status %u)\n",
+                       inst->device, exitcode);
        G.num_running--;
        free_instance(inst);
 
-       return status;
+       return exitcode;
 }
 
 /*