From: Tobias Stoeckmann Date: Mon, 19 Jan 2026 18:18:16 +0000 (+0100) Subject: lib/pager: The variable need_in is always 1 X-Git-Tag: v2.43-devel~136^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=695f8a7171479c0e06a0f342f9dddca0dc36072e;p=thirdparty%2Futil-linux.git lib/pager: The variable need_in is always 1 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 --- diff --git a/lib/pager.c b/lib/pager.c index b0520abcd..95774134e 100644 --- a/lib/pager.c +++ b/lib/pager.c @@ -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; }