[Debconf-devel] Bug#782463: debconf: purging package that uses debconf fails if postrm writes to stdout

Tristan Schmelcher tristan_schmelcher at alumni.uwaterloo.ca
Sun Apr 12 17:19:23 UTC 2015


Package: debconf
Version: 1.5.51
Severity: normal

Packages that use debconf automatically get a postrm fragment for purge that sources confmodule. This breaks if the maintainer has a custom postrm that can write to stdout before the #DEBHELPER# line, because the redirection of stdout to stderr does not occur until the #DEBHELPER# line is reached for the second time. This results in an unpurgeable package. Here is a minimal package that repros the problem:



diff -urN nosuchdir/debian/changelog debconfbugrepro-1.0/debian/changelog
--- nosuchdir/debian/changelog	1969-12-31 19:00:00.000000000 -0500
+++ debconfbugrepro-1.0/debian/changelog	2015-04-12 12:33:57.974322459 -0400
@@ -0,0 +1,5 @@
+debconfbugrepro (1.0) unstable; urgency=low
+
+  * Test.
+
+ -- Nobody <nobody at nowhere>  Sun, 12 Apr 2015 12:33:11 -0400
diff -urN nosuchdir/debian/compat debconfbugrepro-1.0/debian/compat
--- nosuchdir/debian/compat	1969-12-31 19:00:00.000000000 -0500
+++ debconfbugrepro-1.0/debian/compat	2015-04-12 12:29:18.490332697 -0400
@@ -0,0 +1 @@
+9
diff -urN nosuchdir/debian/control debconfbugrepro-1.0/debian/control
--- nosuchdir/debian/control	1969-12-31 19:00:00.000000000 -0500
+++ debconfbugrepro-1.0/debian/control	2015-04-12 12:30:40.090329708 -0400
@@ -0,0 +1,10 @@
+Source: debconfbugrepro
+Section: misc
+Priority: optional
+Maintainer: Nobody <nobody at nowhere>
+Standards-Version: 3.9.6
+
+Package: debconfbugrepro
+Architecture: all
+Description: test
+ Test.
diff -urN nosuchdir/debian/postrm debconfbugrepro-1.0/debian/postrm
--- nosuchdir/debian/postrm	1969-12-31 19:00:00.000000000 -0500
+++ debconfbugrepro-1.0/debian/postrm	2015-04-12 12:31:34.758327706 -0400
@@ -0,0 +1,4 @@
+#!/bin/sh
+echo 'Simulate doing something that writes to stdout'
+#DEBHELPER#
+exit 0
diff -urN nosuchdir/debian/rules debconfbugrepro-1.0/debian/rules
--- nosuchdir/debian/rules	1969-12-31 19:00:00.000000000 -0500
+++ debconfbugrepro-1.0/debian/rules	2015-04-12 12:34:39.242320948 -0400
@@ -0,0 +1,3 @@
+#!/usr/bin/make -f 
+%:
+	dh $@
diff -urN nosuchdir/debian/templates debconfbugrepro-1.0/debian/templates
--- nosuchdir/debian/templates	1969-12-31 19:00:00.000000000 -0500
+++ debconfbugrepro-1.0/debian/templates	2015-04-12 12:32:03.550326651 -0400
@@ -0,0 +1,4 @@
+Template: debconfbugrepro/test
+Type: string
+Description: test
+ Test.



Purging this package fails:

$ sudo dpkg -P debconfbugrepro
(Reading database ... 577471 files and directories currently installed.)
Removing debconfbugrepro (1.0) ...
Simulate doing something that writes to stdout
Purging configuration files for debconfbugrepro (1.0) ...
Simulate doing something that writes to stdout
dpkg: error processing package debconfbugrepro (--purge):
 subprocess installed post-removal script returned error exit status 128
Errors were encountered while processing:
 debconfbugrepro
$



The problem can be fixed by having the re-exec in confmodule go through a helper script to do the redirection before running any maintainer code, such as with this patch:



diff -urN debconf.bak/confmodule debconf/confmodule
--- debconf.bak/confmodule	2015-04-12 13:11:31.850239896 -0400
+++ debconf/confmodule	2015-04-12 13:07:16.898249235 -0400
@@ -12,28 +12,13 @@
 	# Since there is no FrontEnd, this program execs a FrontEnd.
 	# It will then run a new copy of $0 that can talk to it.
 	if [ "$DEBCONF_USE_CDEBCONF" ]; then
-		exec /usr/lib/cdebconf/debconf $0 "$@"
+		exec /usr/lib/cdebconf/debconf /usr/share/debconf/wrapper.sh "$0" "$@"
 	else
-		exec /usr/share/debconf/frontend $0 "$@"
+		exec /usr/share/debconf/frontend /usr/share/debconf/wrapper.sh "$0" "$@"
 	fi
 fi
 
-# Only do this once.
-if [ -z "$DEBCONF_REDIR" ]; then
-	# Redirect standard output to standard error. This prevents common
-	# mistakes by making all the output of the postinst or whatever
-	# script is using this library not be parsed as confmodule commands.
-	#
-	# To actually send something to standard output, send it to fd 3.
-	exec 3>&1
-	if [ "$DEBCONF_USE_CDEBCONF" ]; then
-		exec 1>&5
-	else
-		exec 1>&2
-	fi
-	DEBCONF_REDIR=1
-	export DEBCONF_REDIR
-fi
+. /usr/share/debconf/setup-redir
 
 ###############################################################################
 # Commands.
diff -urN debconf.bak/setup-redir debconf/setup-redir
--- debconf.bak/setup-redir	1969-12-31 19:00:00.000000000 -0500
+++ debconf/setup-redir	2015-04-12 13:03:50.642256791 -0400
@@ -0,0 +1,17 @@
+#!/bin/sh
+# Only do this once.
+if [ -z "$DEBCONF_REDIR" ]; then
+        # Redirect standard output to standard error. This prevents common
+        # mistakes by making all the output of the postinst or whatever
+        # script is using this library not be parsed as confmodule commands.
+        #
+        # To actually send something to standard output, send it to fd 3.
+        exec 3>&1
+        if [ "$DEBCONF_USE_CDEBCONF" ]; then
+                exec 1>&5
+        else
+                exec 1>&2
+        fi
+        DEBCONF_REDIR=1
+        export DEBCONF_REDIR
+fi
diff -urN debconf.bak/wrapper.sh debconf/wrapper.sh
--- debconf.bak/wrapper.sh	1969-12-31 19:00:00.000000000 -0500
+++ debconf/wrapper.sh	2015-04-12 13:05:01.806254184 -0400
@@ -0,0 +1,4 @@
+#!/bin/sh
+# This script wraps the confmodule-using script when passed to the frontend.
+. /usr/share/debconf/setup-redir
+exec "$@"



More information about the Debconf-devel mailing list