]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/pager: Simplify wait_for_pager
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 19 Jan 2026 18:35:48 +0000 (19:35 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 20 Jan 2026 16:36:45 +0000 (17:36 +0100)
Remove unneeded checks and simplify loop to make it easier to see that
the function only waits until the child terminates.

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

index 5ac55fb762d5cab710d193b87e1349221500b8c0..5cafc1e0815bda3bc9b90f711569a415ef944df6 100644 (file)
@@ -97,41 +97,20 @@ static int start_command(struct child_process *cmd)
 
 static void wait_for_pager(void)
 {
-       pid_t pid = pager_process.pid;
+       pid_t waiting;
 
-       if (!pid)
+       if (!pager_process.pid)
                return;
 
        /* signal EOF to pager */
        close(STDOUT_FILENO);
        close(STDERR_FILENO);
 
-       for (;;) {
-               int status, code;
-               pid_t waiting = waitpid(pid, &status, 0);
-
-               if (waiting < 0) {
-                       if (errno == EINTR)
-                               continue;
+       do {
+               waiting = waitpid(pager_process.pid, NULL, 0);
+               if (waiting == -1 && errno != EINTR)
                        ul_sig_err(EXIT_FAILURE, "waitpid failed");
-               }
-               if (waiting != pid)
-                       return;
-               if (WIFSIGNALED(status))
-                       return;
-
-               if (!WIFEXITED(status))
-                       return;
-               code = WEXITSTATUS(status);
-               switch (code) {
-               case 127:
-                       return;
-               case 0:
-                       return;
-               default:
-                       return;
-               }
-       }
+       } while (waiting == -1);
 }
 
 static void wait_for_pager_signal(int signo)