[Pcsclite-cvs-commit] r4700 - in /trunk/PCSC/src: pcscd.h.in pcscdaemon.c winscard_clnt.c winscard_svc.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Tue Feb 2 10:02:55 UTC 2010


Author: rousseau
Date: Tue Feb  2 10:02:52 2010
New Revision: 4700

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=4700
Log:
pcscd will suicide itself after 60 seconds of inactivity if it is
started using --auto-exit
This is the default behavior when pcscd is started by libpcsclite

Modified:
    trunk/PCSC/src/pcscd.h.in
    trunk/PCSC/src/pcscdaemon.c
    trunk/PCSC/src/winscard_clnt.c
    trunk/PCSC/src/winscard_svc.c

Modified: trunk/PCSC/src/pcscd.h.in
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/pcscd.h.in?rev=4700&op=diff
==============================================================================
--- trunk/PCSC/src/pcscd.h.in (original)
+++ trunk/PCSC/src/pcscd.h.in Tue Feb  2 10:02:52 2010
@@ -14,6 +14,8 @@
 
 #ifndef __pcscd_h__
 #define __pcscd_h__
+
+#define TIME_BEFORE_SUICIDE 60
 
 #define SCARD_SCOPE_GLOBAL		0x0003	/**< Scope is global */
 

Modified: trunk/PCSC/src/pcscdaemon.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/pcscdaemon.c?rev=4700&op=diff
==============================================================================
--- trunk/PCSC/src/pcscdaemon.c (original)
+++ trunk/PCSC/src/pcscdaemon.c Tue Feb  2 10:02:52 2010
@@ -54,6 +54,7 @@
 
 char AraKiri = FALSE;
 static char Init = TRUE;
+char AutoExit = FALSE;
 static int ExitValue = EXIT_SUCCESS;
 int HPForceReaderPolling = 0;
 
@@ -208,10 +209,11 @@
 		{"max-thread", 1, NULL, 't'},
 		{"max-card-handle-per-thread", 1, NULL, 's'},
 		{"max-card-handle-per-reader", 1, NULL, 'r'},
+		{"auto-exit", 0, NULL, 'x'},
 		{NULL, 0, NULL, 0}
 	};
 #endif
-#define OPT_STRING "c:fdhvaeCHt:r:s:"
+#define OPT_STRING "c:fdhvaeCHt:r:s:x"
 
 	rv = 0;
 	newReaderConfig = NULL;
@@ -312,6 +314,12 @@
 				customMaxThreadCardHandles = optarg ? atoi(optarg) : 0; 
 				Log2(PCSC_LOG_INFO, "setting customMaxThreadCardHandles to: %d",
 					customMaxThreadCardHandles);
+				break;
+
+			case 'x':
+				AutoExit = TRUE;
+				Log2(PCSC_LOG_INFO, "Auto exit after %d seconds of inactivity",
+					TIME_BEFORE_SUICIDE);
 				break;
 
 			default:
@@ -416,6 +424,9 @@
 	(void)signal(SIGTERM, signal_trap);
 	(void)signal(SIGINT, signal_trap);
 
+	/* exits on SIGALARM to allow pcscd to suicide if not used */
+	(void)signal(SIGALRM, signal_trap);
+
 	/*
 	 * If PCSCLITE_IPC_DIR does not exist then create it
 	 */
@@ -565,9 +576,9 @@
 	HPReCheckSerialReaders();
 } /* signal_reload */
 
-static void signal_trap(/*@unused@*/ int sig)
-{
-	(void)sig;
+static void signal_trap(int sig)
+{
+	Log2(PCSC_LOG_INFO, "Received signal: %d", sig);
 
 	/* the signal handler is called several times for the same Ctrl-C */
 	if (AraKiri == FALSE)

Modified: trunk/PCSC/src/winscard_clnt.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_clnt.c?rev=4700&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_clnt.c (original)
+++ trunk/PCSC/src/winscard_clnt.c Tue Feb  2 10:02:52 2010
@@ -428,7 +428,7 @@
 				int ret;
 
 				/* son process */
-				ret = execl(PCSCD_BINARY, "pcscd", (char *)NULL);
+				ret = execl(PCSCD_BINARY, "pcscd", "--auto-exit", (char *)NULL);
 				Log2(PCSC_LOG_CRITICAL, "exec failed: %s", strerror(errno));
 				exit(1);
 			}

Modified: trunk/PCSC/src/winscard_svc.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_svc.c?rev=4700&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_svc.c (original)
+++ trunk/PCSC/src/winscard_svc.c Tue Feb  2 10:02:52 2010
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <stddef.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include "pcscd.h"
 #include "winscard.h"
@@ -47,6 +48,7 @@
  * An Application Context contains Channels (\c hCard).
  */
 
+extern char AutoExit;
 static unsigned int contextMaxThreadCounter = PCSC_MAX_CONTEXT_THREADS;
 static unsigned int contextMaxCardHandles = PCSC_MAX_CONTEXT_CARD_HANDLES;
 
@@ -203,6 +205,10 @@
 		list_destroy(&(newContext->cardsList));
 		goto error;
 	}
+
+	/* disable any suicide alarm */
+	if (AutoExit)
+		alarm(0);
 
 	return SCARD_S_SUCCESS;
 
@@ -927,5 +933,13 @@
 
 	free(threadContext);
 
+	/* start a suicide alarm */
+	if (AutoExit && (list_size(&contextsList) < 1))
+	{
+		Log2(PCSC_LOG_DEBUG, "Starting suicide alarm in %d seconds",
+			TIME_BEFORE_SUICIDE);
+		alarm(TIME_BEFORE_SUICIDE);
+	}
+
 	return 0;
 }




More information about the Pcsclite-cvs-commit mailing list