[Pcsclite-cvs-commit] r2910 - /trunk/PCSC/src/winscard_clnt.c
rousseau at users.alioth.debian.org
rousseau at users.alioth.debian.org
Thu Apr 24 09:34:54 UTC 2008
Author: rousseau
Date: Thu Apr 24 09:34:54 2008
New Revision: 2910
URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=2910
Log:
SCardCheckDaemonAvailability(): invalidate all handles if the
application has forked and we are in the child. The child must call
SCardEstablishContext() to get his own handle.
Thanks to Alon Bar-Lev for the bug report and the patch
Modified:
trunk/PCSC/src/winscard_clnt.c
Modified: trunk/PCSC/src/winscard_clnt.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_clnt.c?rev=2910&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_clnt.c (original)
+++ trunk/PCSC/src/winscard_clnt.c Thu Apr 24 09:34:54 2008
@@ -191,6 +191,11 @@
*/
static time_t daemon_ctime = 0;
static pid_t daemon_pid = 0;
+/**
+ * PID of the client application.
+ * Used to detect fork() and disable handles in the child process
+ */
+static pid_t client_pid = 0;
/**
* Memory mapped address used to read status information about the readers.
@@ -3487,6 +3492,7 @@
{
LONG rv;
struct stat statBuffer;
+ int after_fork = (client_pid != 0) && (client_pid != getpid());
rv = SYS_Stat(PCSCLITE_PUBSHM_FILE, &statBuffer);
@@ -3497,18 +3503,18 @@
return SCARD_E_NO_SERVICE;
}
- if (daemon_ctime)
+ if (daemon_ctime || after_fork)
{
/* when the _first_ reader is connected the ctime changes
* I don't know why yet */
- if (statBuffer.st_ctime > daemon_ctime)
+ if (statBuffer.st_ctime > daemon_ctime || after_fork)
{
pid_t new_pid;
new_pid = GetDaemonPid();
/* so we also check the daemon pid to be sure it is a new pcscd */
- if (new_pid != daemon_pid)
+ if (new_pid != daemon_pid || after_fork)
{
int i;
@@ -3525,11 +3531,15 @@
/* reset pcscd status */
daemon_ctime = 0;
+ client_pid = 0;
/* reset the lib */
SCardUnload();
- return SCARD_E_NO_SERVICE;
+ if (after_fork)
+ return SCARD_E_INVALID_HANDLE;
+ else
+ return SCARD_E_NO_SERVICE;
}
daemon_ctime = statBuffer.st_ctime;
@@ -3539,6 +3549,7 @@
{
daemon_ctime = statBuffer.st_ctime;
daemon_pid = GetDaemonPid();
+ client_pid = getpid();
}
return SCARD_S_SUCCESS;
More information about the Pcsclite-cvs-commit
mailing list