[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

hint pcsc-lite package because of RC bugs



Hello,

Please Cc: me on reply.

Version 1.3.2-5 of pcsc-lite (binary packages
libpcsclite1_1.3.2-5_i386.deb, pcscd_1.3.2-5_i386.deb and
libpcsclite-dev_1.3.2-5_i386.deb) solves 3 RC bugs: #392357, #404897
and #405025.

These 3 RC bugs are duplicates and concern the way /etc/init.d/pcscd was
written. I completely rewriten this script using /etc/init.d/skeleton as
example. In particular I do not call restart from start any more. This
was causing a fork bomb on some systems.

A complete diff between 1.3.2-3 (in testing) and 1.3.2-5 is bellow.
Note that the file src/tokenparser.c is regenerated by flex from
src/tokenparser.l so the patch is not relevant.

--- pcsc-lite-1.3.2/src/tokenparser.c
+++ pcsc-lite-1.3.2.orig/src/tokenparser.c
@@ -1019,7 +1019,7 @@
 
 		/* Read in more data. */
 		YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+			(yy_n_chars), num_to_read );
-			(yy_n_chars), (size_t) num_to_read );
 
 		YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
 		}
diff -u pcsc-lite-1.3.2/debian/pcscd.init pcsc-lite-1.3.2/debian/pcscd.init
--- pcsc-lite-1.3.2/debian/pcscd.init
+++ pcsc-lite-1.3.2/debian/pcscd.init
@@ -22,73 +22,132 @@
-PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="PCSC Lite resource manager"
 NAME=pcscd
 DAEMON=/usr/sbin/$NAME
-DESC="PCSC Lite resource manager"
 
 PIDFILE=/var/run/$NAME.pid
+PUBFILE=/var/run/$NAME.pub
 SCRIPTNAME=/etc/init.d/$NAME
 
 # Gracefully exit if the package has been removed (but not purged).
-test -x $DAEMON || exit 0
+[ -x "$DAEMON" ] || exit 0
 
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
 . /lib/lsb/init-functions
 
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+	# Return
+	#   0 if daemon has been started
+	#   1 if daemon was already running
+	#   2 if daemon could not be started
+	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
+		|| return 1
+	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
+		$DAEMON_ARGS \
+		|| return 2
+	# Add code here, if necessary, that waits for the process to be ready
+	# to handle requests from services started subsequently which depend
+	# on this one.  As a last resort, sleep for some time.
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+	# Return
+	#   0 if daemon has been stopped
+	#   1 if daemon was already stopped
+	#   2 if daemon could not be stopped
+	#   other if a failure occurred
+	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
+	RETVAL="$?"
+	[ "$RETVAL" = 2 ] && return 2
+	# Wait for children to finish too if this is a daemon that forks
+	# and if the daemon is only ever run from this initscript.
+	# If the above conditions are not satisfied then add some other code
+	# that waits for the process to drop all resources that could be
+	# needed by services started subsequently.  A last resort is to
+	# sleep for some time.
+	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
+	[ "$?" = 2 ] && return 2
+	# Many daemons don't delete their pidfiles when they exit.
+	rm -f $PIDFILE
+	return "$RETVAL"
+}
+
+#
+# Function that sends a SIGHUP to the daemon/service
+#
+do_reload() {
+	#
+	# If the daemon can reload its configuration without
+	# restarting (for example, when it is sent a SIGHUP),
+	# then implement that here.
+	#
+	start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
+	return 0
+}
+
 case "$1" in
   start)
-	log_daemon_msg "Starting $DESC" $NAME
-	# if the daemon is already running we REstart it
-	if [ -f $PIDFILE ]; then
-	  log_progress_msg "already running, "
-	  $0 restart
-	else
-	  start-stop-daemon --start --quiet --pidfile $PIDFILE \
-	    --exec $DAEMON -- --error
-	  log_end_msg $?
-	fi
+	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+	do_start
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
 	;;
-
   stop)
-	log_daemon_msg "Stopping $DESC" $NAME
-	start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE \
-	  --retry 10 --name $NAME
-	log_end_msg $?
-	;;
-
+	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+	do_stop
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  #reload|force-reload)
+	#
+	# If do_reload() is not implemented then leave this commented out
+	# and leave 'force-reload' as an alias for 'restart'.
+	#
+	#log_daemon_msg "Reloading $DESC" "$NAME"
+	#do_reload
+	#log_end_msg $?
+	#;;
   restart|force-reload)
-	$0 stop
-	$0 start
+	#
+	# If the "reload" option is implemented then remove the
+	# 'force-reload' alias
+	#
+	log_daemon_msg "Restarting $DESC" "$NAME"
+	do_stop
+	case "$?" in
+	  0|1)
+		do_start
+		case "$?" in
+			0) log_end_msg 0 ;;
+			1) log_end_msg 1 ;; # Old process is still running
+			*) log_end_msg 1 ;; # Failed to start
+		esac
+		;;
+	  *)
+	  	# Failed to stop
+		log_end_msg 1
+		;;
+	esac
 	;;
-
-  restart-if-running)
-    log_daemon_msg "Restarting $DESC if it is running" $NAME
-	if $0 status &> /dev/null
-	then
-		echo "."
-		$0 restart
-	else
-		log_success_msg " (not running)."
-	fi
-	;;
-
-  status)
-	if [ -e $PIDFILE ] ; then
-		if ps -p $(cat $PIDFILE) &> /dev/null ; then
-			echo "running"
-			exit 0
-		else
-			echo "not running and $PIDFILE exists"
-			exit 1
-		fi
-	else
-		echo "not running"
-		exit 3
-	fi
-	;;
-
   *)
-	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|restart-if-running|status}" >&2
-	exit 1
+	#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
+	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
+	exit 3
 	;;
 esac
 
-exit 0
-
+:
diff -u pcsc-lite-1.3.2/debian/pcscd.install pcsc-lite-1.3.2/debian/pcscd.install
--- pcsc-lite-1.3.2/debian/pcscd.install
+++ pcsc-lite-1.3.2/debian/pcscd.install
@@ -1,4 +1,3 @@
 etc/reader.conf.d/0comments
-usr/bin/formaticc
 usr/sbin/pcscd
 usr/sbin/update-reader.conf
diff -u pcsc-lite-1.3.2/debian/control pcsc-lite-1.3.2/debian/control
--- pcsc-lite-1.3.2/debian/control
+++ pcsc-lite-1.3.2/debian/control
@@ -8,7 +8,7 @@
 Package: pcscd
 Architecture: any
 Priority: extra
-Depends: libccid | pcsc-ifd-handler, ${shlibs:Depends}, lsb-base
+Depends: libccid | pcsc-ifd-handler, ${shlibs:Depends}, lsb-base (>= 3.0-6)
 Conflicts: libpcsclite0 (<< 1.2.0-rc1-1), libccid (<= 1.0.0-1)
 Description: Middleware to access a smart card using PC/SC (daemon side)
  The purpose of PC/SC Lite is to provide a Windows(R) SCard interface
diff -u pcsc-lite-1.3.2/debian/changelog pcsc-lite-1.3.2/debian/changelog
--- pcsc-lite-1.3.2/debian/changelog
+++ pcsc-lite-1.3.2/debian/changelog
@@ -1,3 +1,38 @@
+pcsc-lite (1.3.2-5) unstable; urgency=high
+
+  * debian/pcscd.init: rewrite using /etc/init.d/skeleton as example.
+    start rule do not call restart any more
+    Closes: #404897 "pcscd: infinite loop when trying to start the daemon"
+    Closes: #405025 "/etc/init.d/pcscd is a fork bomb"
+
+ -- Ludovic Rousseau <rousseau@debian.org>  Sat, 30 Dec 2006 18:37:45 +0100
+
+pcsc-lite (1.3.2-4) unstable; urgency=low
+
+  * ack and improve Steinar patch
+  * debian/pcscd.init: 
+   - status command: remove /var/run/pcscd.{pid,pub} if pcscd is not running
+     but /var/run/pcscd.pid is still present (pcscd may have crashed)
+   - start comand: call status to know if we start or restart
+
+ -- Ludovic Rousseau <rousseau@debian.org>  Tue, 26 Dec 2006 15:30:18 +0100
+
+pcsc-lite (1.3.2-3.1) unstable; urgency=high
+
+  * Non-maintainer upload.
+  * Fix issues with looping init script. (Closes: #392357)
+    * restart calls stop ; start, but start calls restart if the pid file
+      still exists. This is obviously not a good idea if stop doesn't remove
+      the pid file properly. Make start stop the daemon itself instead of
+      calling restart, which kills the loop.
+    * Also, make the stop target rm -f the pid file after calling
+      start-stop-daemon, just in case, and to avoid extraneous stops from the
+      start target.
+    * Finally, also check and rm /var/run/pcscd.pub, as the daemon doesn't
+      like starting if it's already there.
+
+ -- Steinar H. Gunderson <sesse@debian.org>  Tue, 26 Dec 2006 13:45:25 +0100
+
 pcsc-lite (1.3.2-3) unstable; urgency=high
 
   * urgency high to correct a RC bug
-- 
 Dr. Ludovic Rousseau                        Ludovic.Rousseau@free.fr
 -- Normaliser Unix c'est comme pasteuriser le camembert, L.R. --



Reply to: