]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/pager: Fix SIGPIPE handling
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 4 Apr 2026 08:07:53 +0000 (10:07 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 4 Apr 2026 08:07:53 +0000 (10:07 +0200)
Reset the child pid only after comparison with waitpid result.
Currently, this leads to returning -1 or 1, which ultimately leads
to exit code 1 in case of a SIGPIPE. This is the behavior as of 2.41,
which means that no regression between releases occurred. Yet, fix it
nonetheless.

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

index b24fa2f645948fc97a86396b86f5ee4670171709..64a0a3a6b52e4c1be444aa1e1ed592b96f0dbef1 100644 (file)
@@ -120,21 +120,22 @@ static int start_command(struct child_process *cmd)
 static int wait_for_pager(void)
 {
        pid_t waiting;
-       int status;
+       int ret, status;
 
        do {
                waiting = waitpid(pager_process.pid, &status, 0);
        } while (waiting == -1 && errno == EINTR);
 
-       pager_process.pid = 0;
-
        if (waiting == -1)
-               return -1;
+               ret = -1;
+       else if (waiting == pager_process.pid && WIFEXITED(status))
+               ret = WEXITSTATUS(status);
+       else
+               ret = 1;
 
-       if (waiting == pager_process.pid && WIFEXITED(status))
-               return WEXITSTATUS(status);
+       pager_process.pid = 0;
 
-       return 1;
+       return ret;
 }
 
 static void catch_signal(int signo)