[Pcsclite-cvs-commit] r6027 - /trunk/PCSC/src/pcscdaemon.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Tue Oct 11 13:59:36 UTC 2011


Author: rousseau
Date: Tue Oct 11 13:59:35 2011
New Revision: 6027

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=6027
Log:
main(): store the pid _after_ any fork

Revision 6019 moved the AutoExit fork+exit later in the code. We now
must move the pcscd.pid file creation after the fork+exit.

Modified:
    trunk/PCSC/src/pcscdaemon.c

Modified: trunk/PCSC/src/pcscdaemon.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/pcscdaemon.c?rev=6027&op=diff
==============================================================================
--- trunk/PCSC/src/pcscdaemon.c (original)
+++ trunk/PCSC/src/pcscdaemon.c Tue Oct 11 13:59:35 2011
@@ -501,8 +501,59 @@
 	}
 
 	/*
+	 * Allocate memory for reader structures
+	 */
+	rv = RFAllocateReaderSpace(customMaxReaderHandles);
+	if (SCARD_S_SUCCESS != rv)
+		at_exit();
+
+#ifdef USE_SERIAL
+	/*
+	 * Grab the information from the reader.conf
+	 */
+	if (newReaderConfig)
+	{
+		rv = RFStartSerialReaders(newReaderConfig);
+		if (rv != 0)
+		{
+			Log3(PCSC_LOG_CRITICAL, "invalid file %s: %s", newReaderConfig,
+				strerror(errno));
+			at_exit();
+		}
+	}
+	else
+	{
+		rv = RFStartSerialReaders(PCSCLITE_CONFIG_DIR);
+		if (rv == -1)
+			at_exit();
+	}
+#endif
+
+	Log1(PCSC_LOG_INFO, "pcsc-lite " VERSION " daemon ready.");
+
+	if (AutoExit)
+	{
+		int pid;
+
+		/* create a new session so that Ctrl-C on the application will
+		 * not also quit pcscd */
+		setsid();
+
+		/* fork() so that pcscd always return in --auto-exit mode */
+		pid = fork();
+		if (-1 == pid )
+			Log2(PCSC_LOG_CRITICAL, "fork() failed: %s", strerror(errno));
+
+		if (pid)
+			/* father */
+			return EXIT_SUCCESS;
+	}
+
+	/*
 	 * Record our pid to make it easier
 	 * to kill the correct pcscd
+	 *
+	 * Do not fork after this point or the stored pid will be wrong
 	 */
 	{
 		int f;
@@ -525,55 +576,6 @@
 		else
 			Log2(PCSC_LOG_CRITICAL, "cannot create " PCSCLITE_RUN_PID ": %s",
 				strerror(errno));
-	}
-
-	/*
-	 * Allocate memory for reader structures
-	 */
-	rv = RFAllocateReaderSpace(customMaxReaderHandles);
-	if (SCARD_S_SUCCESS != rv)
-		at_exit();
-
-#ifdef USE_SERIAL
-	/*
-	 * Grab the information from the reader.conf
-	 */
-	if (newReaderConfig)
-	{
-		rv = RFStartSerialReaders(newReaderConfig);
-		if (rv != 0)
-		{
-			Log3(PCSC_LOG_CRITICAL, "invalid file %s: %s", newReaderConfig,
-				strerror(errno));
-			at_exit();
-		}
-	}
-	else
-	{
-		rv = RFStartSerialReaders(PCSCLITE_CONFIG_DIR);
-		if (rv == -1)
-			at_exit();
-	}
-#endif
-
-	Log1(PCSC_LOG_INFO, "pcsc-lite " VERSION " daemon ready.");
-
-	if (AutoExit)
-	{
-		int pid;
-
-		/* create a new session so that Ctrl-C on the application will
-		 * not also quit pcscd */
-		setsid();
-
-		/* fork() so that pcscd always return in --auto-exit mode */
-		pid = fork();
-		if (-1 == pid )
-			Log2(PCSC_LOG_CRITICAL, "fork() failed: %s", strerror(errno));
-
-		if (pid)
-			/* father */
-			return EXIT_SUCCESS;
 	}
 
 	/*




More information about the Pcsclite-cvs-commit mailing list