Hi Colin,

Thank you for taking a look at this one. It has been reported in
Launchpad as well [0].
A summary of how we can trigger this bug would be like this:

- dpkg/apt triggers a package upgrade
- some maintainer scripts are executed with the 'run-parts' tool using
the '--report' flag (e.g. the /etc/kernel/postinst.d scripts at the
end of [1])
- run-parts sets up pipes and captures stdout/stderr from debconf
- readline frontend prints prompt before run-parts can process the
options from stdout pipe

I belive we could fix this by forcing readline to always use stdout if
both stdout and stderr are pipes (since that most likely means debconf
is running under run-parts).
>From what I've tested, the attached patch works correctly for this
case. Do you think that patch would be an appropriate solution?

Thanks,
Heitor

[0] https://bugs.launchpad.net/bugs/1822270
[1] https://termbin.com/c92p
From bbfe0bb54ccf8e6f6cacfd642687e550a2ec5493 Mon Sep 17 00:00:00 2001
From: Heitor Alves de Siqueira <hal...@canonical.com>
Date: Mon, 29 Apr 2019 12:32:01 -0300
Subject: [PATCH] [RFC] debconf: fix readline prompt for run-parts

Signed-off-by: Heitor Alves de Siqueira <hal...@canonical.com>
---
 Debconf/FrontEnd/Readline.pm | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Debconf/FrontEnd/Readline.pm b/Debconf/FrontEnd/Readline.pm
index 546a0be32512..e4868d9be278 100644
--- a/Debconf/FrontEnd/Readline.pm
+++ b/Debconf/FrontEnd/Readline.pm
@@ -48,7 +48,12 @@ sub init {
 	close TESTTY;
 
 	$Term::ReadLine::termcap_nowarn = 1; # Turn off stupid termcap warning.
-	$this->readline(Term::ReadLine->new('debconf'));
+    if (-p STDOUT && -p STDERR) { # make readline play nice with run-parts --report
+        $this->readline(Term::ReadLine->new('debconf', *STDIN, *STDOUT));
+    }
+    else {
+        $this->readline(Term::ReadLine->new('debconf'));
+    }
 	$this->readline->ornaments(1);
 
 	if (Term::ReadLine->ReadLine =~ /::Gnu$/) {
-- 
2.21.0

Reply via email to