[Pcsclite-cvs-commit] r4949 - /trunk/PCSC/src/hotplug_libusb.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Mon May 17 14:54:49 UTC 2010


Author: rousseau
Date: Mon May 17 14:54:47 2010
New Revision: 4949

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=4949
Log:
Add a synchronisation so that if pcscd is auto started the initial
reader list is available before the server takes commands from clients.

Before the change early calls of SCardListReaders() returned an empty
list of readers even if a reader was connected.

Thanks to Patrice Angelini for the bug report

Modified:
    trunk/PCSC/src/hotplug_libusb.c

Modified: trunk/PCSC/src/hotplug_libusb.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/hotplug_libusb.c?rev=4949&op=diff
==============================================================================
--- trunk/PCSC/src/hotplug_libusb.c (original)
+++ trunk/PCSC/src/hotplug_libusb.c Mon May 17 14:54:47 2010
@@ -97,7 +97,7 @@
 	struct _driverTracker *driver);
 static LONG HPRemoveHotPluggable(int reader_index);
 static void HPRescanUsbBus(void);
-static void HPEstablishUSBNotifications(void);
+static void HPEstablishUSBNotifications(int pipefd[2]);
 
 static LONG HPReadBundleValues(void)
 {
@@ -383,9 +383,10 @@
 	}
 }
 
-static void HPEstablishUSBNotifications(void)
+static void HPEstablishUSBNotifications(int pipefd[2])
 {
 	int i, do_polling;
+	char c = 42;	/* magic value */
 
 	/* libusb default is /dev/bus/usb but the devices are not yet visible there
 	 * when a hotplug is requested */
@@ -395,6 +396,10 @@
 
 	/* scan the USB bus for devices at startup */
 	HPRescanUsbBus();
+
+	/* signal that the initially connected readers are now visible */
+	write(pipefd[1], &c, 1);
+	close(pipefd[1]);
 
 	/* if at least one driver do not have IFD_GENERATE_HOTPLUG */
 	do_polling = FALSE;
@@ -447,6 +452,8 @@
 LONG HPSearchHotPluggables(void)
 {
 	int i;
+	int pipefd[2];
+	char c;
 
 	for (i=0; i<PCSCLITE_MAX_READERS_CONTEXTS; i++)
 	{
@@ -455,9 +462,19 @@
 		readerTracker[i].fullName = NULL;
 	}
 
+	if (pipe(pipefd) == -1)
+	{
+		Log2(PCSC_LOG_ERROR, "pipe: %s", strerror(errno));
+		return -1;
+	}
+
 	if (HPReadBundleValues())
 		ThreadCreate(&usbNotifyThread, THREAD_ATTR_DETACHED,
-			(PCSCLITE_THREAD_FUNCTION( )) HPEstablishUSBNotifications, NULL);
+			(PCSCLITE_THREAD_FUNCTION( )) HPEstablishUSBNotifications, pipefd);
+
+	/* Wait for initial readers to setup */
+	read(pipefd[0], &c, 1);
+	close(pipefd[0]);
 
 	return 0;
 }




More information about the Pcsclite-cvs-commit mailing list