From bfac7035a8d1747cfd605d4b7fdf4e0600dc8897 Mon Sep 17 00:00:00 2001 From: Alexey Romanov Date: Mon, 2 Mar 2026 17:09:46 +0300 Subject: [PATCH] actions: restore stderr for interactive pkg_add prompts Without verbosity (-V), pkg_add's interactive prompts (e.g., unsigned package confirmation) were invisible because stderr was redirected to the log file. This made installations appear to hang while waiting for user input. Fix by temporarily restoring original stderr before running pkg_add, then redirecting it back to the log afterward. Ensures prompts are visible on the terminal without affecting logging. Signed-off-by: Alexey Romanov --- actions.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/actions.c b/actions.c index b373b65..5ff21e4 100644 --- a/actions.c +++ b/actions.c @@ -41,6 +41,7 @@ static int warn_count = 0, err_count = 0; static uint8_t said = 0; +static int saved_stderr = -1; FILE *err_fp = NULL; long int rm_filepos = -1; char pkgtools_flags[5]; @@ -229,6 +230,7 @@ open_pi_log(void) exit(EXIT_FAILURE); } + saved_stderr = dup(STDERR_FILENO); dup2(fileno(err_fp), STDERR_FILENO); rm_filepos = ftell(err_fp); @@ -240,6 +242,11 @@ static void close_pi_log(int output) { if (!verbosity && output) { + if (saved_stderr != -1) { + dup2(saved_stderr, STDERR_FILENO); + close(saved_stderr); + saved_stderr = -1; + } analyse_pkglog(rm_filepos); printf(MSG_WARNS_ERRS, warn_count, err_count); if (warn_count > 0 || err_count > 0) @@ -432,9 +439,22 @@ do_pkg_install(Plisthead *installhead) log_tag("[%d/%d] %s %s...\n", i++, count, action, p->ipkg->rpkg->full); + + /* + * Temporarily restore stderr to the terminal so that + * any interactive prompts from pkg_add (e.g. signature + * verification) are visible to the user. + */ + if (saved_stderr != -1) + dup2(saved_stderr, STDERR_FILENO); + if (fexec(pkg_add, pflags, p->ipkg->pkgfs, NULL) == EXIT_FAILURE) rc = EXIT_FAILURE; + + /* Redirect stderr back to the logfile */ + if (!verbosity && err_fp != NULL) + dup2(fileno(err_fp), STDERR_FILENO); } close_pi_log(1);