Subject: fix for debconf stdin bug

From: Blars Blarson <[email-masked]>
Date: Wed, 7 Jan 2004 20:12:20 -0800

package debconf
merge 142944 194152
tags 142944 + patch
thanks

Here is a tested patch to fix the long-standing bug in debconf where
it doesn't restore stdin.  It also closes the extranious fd 3 when it
is no longer needed.

Note that this is less work than a reasonably correct and mostly
working fix for the bug in a single package that uses both debconf and
ucf.

Your claims that is bug is documended in debconf-devel(7) are false.
There is no workaround there either.

--- confmodule.save	2004-01-05 19:52:20.000000000 -0800
+++ confmodule	2004-01-07 19:53:39.000000000 -0800
@@ -7,6 +7,12 @@
 
 # Check to see if a FrontEnd is running.
 if [ ! "$DEBIAN_HAS_FRONTEND" ]; then
+	if [ ! "$DEBCONF_SAVED_STDIN" ] ; then  
+		# save stdin
+		exec 4<&0  
+		DEBCONF_SAVED_STDIN=1
+		export DEBCONF_SAVED_STDIN
+	fi
 	# Ok, this is pretty crazy. Since there is no FrontEnd, this
 	# program execs a FrontEnd. It will then run a new copy of $0 that
 	# can talk to it.
@@ -67,4 +73,11 @@
 # Cannot read a return code, since there is none and we would block.
 db_stop () {
 	echo STOP >&3
+	exec 3>&-
+	if [ "$DEBCONF_SAVED_STDIN" ] ; then
+		exec 0<&4 4<&-
+	else
+		# needed by dpkg-reconfigure 
+		exec 0</dev/tty
+	fi
 }

---

From: Joey Hess <[email-masked]>
Date: Thu, 8 Jan 2004 12:56:29 -0500

> +		exec 4<&0  

This will likely cause every postinst that uses debconf, starts a
daemon, does not call STOP, and only works around closing cd 3 to hang.

-- 
see shy jo

---

From: Blars Blarson <[email-masked]>
Date: Sat, 10 Jan 2004 07:18:57 -0800

> daemon, does not call STOP, and only works around closing cd 3 to hang.

Of the 78 packages I found that use debconf, don't do db_stop, and use
one of start-stop-daemon, invoke-rc.d, and /etc/init.d/ , I don't see
anything that works around your leaving fd 3 open.  Some daemons will
close extranious file descriptors they are passed, but that should
handle fd 4 as well.

Why would having an extra file-descriptor open for reading (probably
from /dev/tty or /dev/null) cause the postinst to hang?

-- 
Blars Blarson			[email-masked]
				http://www.blars.org/blars.html
With Microsoft, failure is not an option.  It is a standard feature.