Skip to content

Commit bfac703

Browse files
committed
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 <romanov.alexey2000@gmail.com>
1 parent b1743be commit bfac703

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

actions.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
static int warn_count = 0, err_count = 0;
4343
static uint8_t said = 0;
44+
static int saved_stderr = -1;
4445
FILE *err_fp = NULL;
4546
long int rm_filepos = -1;
4647
char pkgtools_flags[5];
@@ -229,6 +230,7 @@ open_pi_log(void)
229230
exit(EXIT_FAILURE);
230231
}
231232

233+
saved_stderr = dup(STDERR_FILENO);
232234
dup2(fileno(err_fp), STDERR_FILENO);
233235

234236
rm_filepos = ftell(err_fp);
@@ -240,6 +242,11 @@ static void
240242
close_pi_log(int output)
241243
{
242244
if (!verbosity && output) {
245+
if (saved_stderr != -1) {
246+
dup2(saved_stderr, STDERR_FILENO);
247+
close(saved_stderr);
248+
saved_stderr = -1;
249+
}
243250
analyse_pkglog(rm_filepos);
244251
printf(MSG_WARNS_ERRS, warn_count, err_count);
245252
if (warn_count > 0 || err_count > 0)
@@ -432,9 +439,22 @@ do_pkg_install(Plisthead *installhead)
432439

433440
log_tag("[%d/%d] %s %s...\n", i++, count, action,
434441
p->ipkg->rpkg->full);
442+
443+
/*
444+
* Temporarily restore stderr to the terminal so that
445+
* any interactive prompts from pkg_add (e.g. signature
446+
* verification) are visible to the user.
447+
*/
448+
if (saved_stderr != -1)
449+
dup2(saved_stderr, STDERR_FILENO);
450+
435451
if (fexec(pkg_add, pflags, p->ipkg->pkgfs, NULL)
436452
== EXIT_FAILURE)
437453
rc = EXIT_FAILURE;
454+
455+
/* Redirect stderr back to the logfile */
456+
if (!verbosity && err_fp != NULL)
457+
dup2(fileno(err_fp), STDERR_FILENO);
438458
}
439459

440460
close_pi_log(1);

0 commit comments

Comments
 (0)