]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/pager: Merge wait_or_whine into wait_for_pager
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 19 Jan 2026 18:25:30 +0000 (19:25 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 20 Jan 2026 16:36:45 +0000 (17:36 +0100)
Move code from wait_or_whine into wait_for_pager to simplify code by
clarifying where values come from (pid is pager_process.pid).

Also, it shows that return values are actually not used.

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

index 95774134eae6224cd232e438a50845fadcf05cae..5ac55fb762d5cab710d193b87e1349221500b8c0 100644 (file)
@@ -95,8 +95,17 @@ static int start_command(struct child_process *cmd)
        return 0;
 }
 
-static int wait_or_whine(pid_t pid)
+static void wait_for_pager(void)
 {
+       pid_t pid = pager_process.pid;
+
+       if (!pid)
+               return;
+
+       /* signal EOF to pager */
+       close(STDOUT_FILENO);
+       close(STDERR_FILENO);
+
        for (;;) {
                int status, code;
                pid_t waiting = waitpid(pid, &status, 0);
@@ -107,40 +116,24 @@ static int wait_or_whine(pid_t pid)
                        ul_sig_err(EXIT_FAILURE, "waitpid failed");
                }
                if (waiting != pid)
-                       return -1;
+                       return;
                if (WIFSIGNALED(status))
-                       return -1;
+                       return;
 
                if (!WIFEXITED(status))
-                       return -1;
+                       return;
                code = WEXITSTATUS(status);
                switch (code) {
                case 127:
-                       return -1;
+                       return;
                case 0:
-                       return 0;
+                       return;
                default:
-                       return -1;
+                       return;
                }
        }
 }
 
-static int finish_command(struct child_process *cmd)
-{
-       return wait_or_whine(cmd->pid);
-}
-
-static void wait_for_pager(void)
-{
-       if (pager_process.pid == 0)
-               return;
-
-       /* signal EOF to pager */
-       close(STDOUT_FILENO);
-       close(STDERR_FILENO);
-       finish_command(&pager_process);
-}
-
 static void wait_for_pager_signal(int signo)
 {
        UL_PROTECT_ERRNO;