]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
eject: Reset SIGCHLD to default for wait
authorTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 6 Mar 2026 20:58:46 +0000 (21:58 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Fri, 6 Mar 2026 21:01:02 +0000 (22:01 +0100)
If SIGCHLD is ignored, the wait call which waits for the umount command
to finish could fail with -1 and ECHILD. Since its return value is not
checked, the uninitialized status variable would be read, leading to
undefined behavior.

While at it, removed the additionally printed newline from errx message.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
sys-utils/eject.c

index 0debd0df334f3d26a14c1cda0c5ca17103a9af1a..5d6328312d09afbad0811a642116442a3cce5f76 100644 (file)
@@ -671,13 +671,12 @@ static void umount_one(const struct eject_control *ctl, const char *name)
                break;
 
        default: /* parent */
-               wait(&status);
-               if (WIFEXITED(status) == 0)
+               if (wait(&status) == -1 || WIFEXITED(status) == 0)
                        errx(EXIT_FAILURE,
                             _("unmount of `%s' did not exit normally"), name);
 
                if (WEXITSTATUS(status) != 0)
-                       errx(EXIT_FAILURE, _("unmount of `%s' failed\n"), name);
+                       errx(EXIT_FAILURE, _("unmount of `%s' failed"), name);
                break;
        }
 }
@@ -863,6 +862,9 @@ int main(int argc, char **argv)
                return EXIT_SUCCESS;
        }
 
+       /* clear any inherited settings */
+       signal(SIGCHLD, SIG_DFL);
+
        if (!ctl.device) {
                ctl.device = mnt_resolve_path(EJECT_DEFAULT_DEVICE, NULL);
                verbose(&ctl, _("using default device `%s'"), ctl.device);