]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/pager: The variable need_in is always 1
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 19 Jan 2026 18:18:16 +0000 (19:18 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 20 Jan 2026 16:36:45 +0000 (17:36 +0100)
Right before start_command is called, cmd->in is set to -1. Thus,
need_in is always true.

This makes sense, since we create a pipe for tools to print data to
pager.

Remove obsolete code for better readability.

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

index b0520abcd35527c5a50ee93337111a2c344d9484..95774134eae6224cd232e438a50845fadcf05cae 100644 (file)
@@ -69,30 +69,17 @@ static void pager_preexec(void)
 
 static int start_command(struct child_process *cmd)
 {
-       int need_in;
        int fdin[2];
 
-       /*
-        * In case of errors we must keep the promise to close FD
-        * that has been passed in via ->in.
-        */
-       need_in = cmd->in < 0;
-       if (need_in) {
-               if (pipe(fdin) < 0)
-                       return -1;
-               cmd->in = fdin[1];
-       }
+       if (pipe(fdin) < 0)
+               return -1;
+       cmd->in = fdin[1];
 
        fflush(NULL);
        cmd->pid = fork();
        if (!cmd->pid) {
-               if (need_in) {
-                       dup2(fdin[0], STDIN_FILENO);
-                       close_pair(fdin);
-               } else if (cmd->in > 0) {
-                       dup2(cmd->in, STDIN_FILENO);
-                       close(cmd->in);
-               }
+               dup2(fdin[0], STDIN_FILENO);
+               close_pair(fdin);
 
                pager_preexec();
                execvp(cmd->argv[0], (char *const*) cmd->argv);
@@ -100,17 +87,11 @@ static int start_command(struct child_process *cmd)
        }
 
        if (cmd->pid < 0) {
-               if (need_in)
-                       close_pair(fdin);
-               else if (0 <= cmd->in)
-                       close(cmd->in);
+               close_pair(fdin);
                return -1;
        }
 
-       if (need_in)
-               close(fdin[0]);
-       else if (0 <= cmd->in)
-               close(cmd->in);
+       close(fdin[0]);
        return 0;
 }