]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/pager: Set SIGCHLD to default handling
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 2 Feb 2026 19:07:35 +0000 (20:07 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 2 Feb 2026 19:07:35 +0000 (20:07 +0100)
If SIGCHLD is ignored, then waitpid might return an error if child
process is already terminated, since zombie process generation would be
blocked.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
lib/pager.c

index 9cbf6383f5ea5b27bb97aae5a7770b3a73020497..de4c2113c078397467ad745dee7b9f2142eff089 100644 (file)
@@ -35,6 +35,7 @@ struct child_process {
 
        int org_err;
        int org_out;
+       struct sigaction orig_sigchld;
        struct sigaction orig_sigint;
        struct sigaction orig_sighup;
        struct sigaction orig_sigterm;
@@ -186,6 +187,12 @@ static void __setup_pager(void)
        pager_process.argv = pager_argv;
        pager_process.in = -1;
 
+       memset(&sa, 0, sizeof(sa));
+       sa.sa_handler = SIG_DFL;
+
+       /* this makes sure that waitpid works as expected */
+       sigaction(SIGCHLD, &sa, &pager_process.orig_sigchld);
+
        if (start_command(&pager_process))
                return;
 
@@ -198,7 +205,6 @@ static void __setup_pager(void)
        }
        close(pager_process.in);
 
-       memset(&sa, 0, sizeof(sa));
        sa.sa_handler = wait_for_pager_signal;
 
        /* this makes sure that the parent terminates after the pager */
@@ -251,6 +257,7 @@ void pager_close(void)
        close(pager_process.org_err);
 
        /* restore original signal settings */
+       sigaction(SIGCHLD, &pager_process.orig_sigchld, NULL);
        sigaction(SIGINT,  &pager_process.orig_sigint, NULL);
        sigaction(SIGHUP,  &pager_process.orig_sighup, NULL);
        sigaction(SIGTERM, &pager_process.orig_sigterm, NULL);