tags 500570 patch
tags 437535 patch
thanks
Interfaces listed in HOTPLUG_INTERFACES configuration variable are not handled
at all during package reconfiguration or removal.
The ifplugd initscript is designed to start/stop only interfaces listed in the
INTERFACES configuration variable, but it does take interface name(s) as extra
arguments to the action. This property can be used to advantage in the package
maintainer scripts to improve ifplugd reconfiguration, rather than just using
the universal debhelper generated initscript handling code.
To do this, in postinst we can compare the list of interfaces in
INTERFACES + HOTPLUG_INTERFACES configuration before and after the new
configuration is written to /etc/default/ifplugd. With these two lists, it is
possible to:
1) stop ifplugd instances for interfaces that have been removed from the new
ifplugd configuration but were present in the previous configuration
2) restart ifplugd instances for interfaces present in old and new
configuration, as the options may have changed or package upgrade requires
restart
3) start ifplugd instances for instances which are added to the new
configuration
In the prerm maintainer script, avoid stopping ifplugd instances except for
package removal. When package is being removed, source the current
configuration and add $INTERFACES and $HOTPLUG_INTERFACES variable to argument
of initscript stop action, so ifplugd instances are stopped for all configured
interfaces, not just the statically managed ones.
Because dh_installinit --noscripts is used, care must be taken to manage the
update-rc.d calls in postinst and postrm too.
As #219000 mentions, tighter control of the options given to ifplugd is
probably required to make this process even more robust and lead to a solution
for that bug report.
Closes: #500570, #437535
---
--- a/debian/postinst
+++ b/debian/postinst
@@ -50,11 +50,84 @@
mv ${DEFAULTTMP} ${DEFAULTFILE}
}
+INTERFACES_BEFORE=""
+INTERFACES_AFTER=""
+INTERFACES_START=""
+INTERFACES_STOP=""
+INTERFACES_RESTART=""
+
+search_interfaces () {
+ searchifc=$1
+ shift
+
+ for i in $@; do
+ if [ "$i" = "$searchifc" ]; then
+ return 0
+ fi
+ done
+
+ return 1
+}
+
+ifplugd_initscript () {
+ action=$1
+ shift
+
+ if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
+ invoke-rc.d ifplugd $action $@
+ else
+ /etc/init.d/ifplugd $action $@
+ fi
+}
+
case "$1" in
configure)
-
+ if [ -s "$DEFAULTFILE" ] ; then
+ INTERFACES=""
+ HOTPLUG_INTERFACES=""
+ . $DEFAULTFILE
+ INTERFACES_BEFORE="$INTERFACES $HOTPLUG_INTERFACES"
+ fi
+
write_db_conf
write_default
+
+ if [ -s "$DEFAULTFILE" ] ; then
+ INTERFACES=""
+ HOTPLUG_INTERFACES=""
+ . $DEFAULTFILE
+ INTERFACES_AFTER="$INTERFACES $HOTPLUG_INTERFACES"
+ fi
+
+ for IF in $INTERFACES_BEFORE ; do
+ if search_interfaces $IF $INTERFACES_AFTER ; then
+ INTERFACES_RESTART="$INTERFACES_RESTART $IF"
+ else
+ INTERFACES_STOP="$INTERFACES_STOP $IF"
+ fi
+ done
+
+ for IF in $INTERFACES_AFTER ; do
+ if search_interfaces $IF $INTERFACES_BEFORE ; then
+ : # already added to INTERFACES_RESTART
+ else
+ INTERFACES_START="$INTERFACES_START $IF"
+ fi
+ done
+
+ if [ -x "/etc/init.d/ifplugd" ]; then
+ update-rc.d ifplugd defaults >/dev/null
+ if [ "$INTERFACES_STOP" ]; then
+ ifplugd_initscript stop $INTERFACES_STOP
+ fi
+ if [ "$INTERFACES_RESTART" ]; then
+ ifplugd_initscript restart $INTERFACES_RESTART
+ fi
+ if [ "$INTERFACES_START" ]; then
+ ifplugd_initscript start $INTERFACES_START
+ fi
+ fi
+
if [ ! "$2" ] || [ "$2" = "<unknown>" ] ; then
# Fresh install
for F in /etc/apm/suspend.d/20ifplugd \
--- a/debian/rules
+++ b/debian/rules
@@ -80,7 +80,7 @@
dh_installchangelogs doc/ChangeLog
dh_installdocs
dh_installdebconf
- dh_installinit
+ dh_installinit --noscripts
dh_installudev
dh_installman
dh_link
--- /dev/null
+++ b/debian/prerm
@@ -0,0 +1,19 @@
+#!/bin/sh -e
+
+DEFAULTFILE=/etc/default/ifplugd
+INTERFACES=""
+HOTPLUG_INTERFACES=""
+
+if [ -s "$DEFAULTFILE" ]; then
+ . $DEFAULTFILE
+fi
+
+if [ -x "/etc/init.d/ifplugd" ] && [ "$1" = remove ]; then
+ if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
+ invoke-rc.d ifplugd stop $INTERFACES $HOTPLUG_INTERFACES
+ else
+ /etc/init.d/ifplugd stop $INTERFACES $HOTPLUG_INTERFACES
+ fi
+fi
+
+#DEBHELPER#
--- a/debian/postrm
+++ b/debian/postrm
@@ -18,6 +18,8 @@
for f in /etc/apm/suspend.d/20ifplugd /etc/apm/resume.d/80ifplugd
/etc/apm/other.d/50ifplugd ; do
rm -f $f
done
+
+ update-rc.d ifplugd remove >/dev/null
;;
remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
---
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]