<div dir="ltr"><div><div><div><div><div><div>Dear readers,<br><br></div>One of may smartcard application running under Mac OS-X suddenly stopped<br></div>working. The application does a fork() unless started in debug-mode. It took<br></div>me quite a while until I found:<br><br><a href="http://ludovicrousseau.blogspot.de/2015/01/os-x-yosemite-bug-pcsc-functions-crash.html" target="_blank">http://ludovicrousseau.blogspot.de/2015/01/os-x-yosemite-bug-pcsc-functions-crash.html</a><br><br></div>It's always fun to search for a bug that disappears if you switch on<br></div>debug-mode :-)<br><br></div><div>Here's what Ludivic writes in his blog:<br><br>"I verified this behaviour only with <code>SCardListReaders()</code> and <code>SCardConnect()</code>.<br>I would not be surprised if it is the case for all PC/SC functions (except <code>SCardEstablishContext()</code> of course)."<br><br></div><div>Maybe this will surpise you: Under OS-X Yosemite EVERY PC/SC-function will crash in<br>a child process if SCardEstablishContext() was called in the parent process<br>INCLUDING SCardEstablishContext() itself.<br><br></div><div>If SCardEstablishContext() was not called in a parent process<br>SCardEstablishContext() will fail in a child process with "Service not available"<br><br></div>So if you are running a daemon that forks child processes your cannot use<br>pcsclite anymore from these child processes no matter what you try.<br><br>Any ideas??<br><br>Kind reagrds<br><br>Peter Koch<br><br>#include <stdlib.h><br>#include <stdio.h><br>#include <unistd.h><br>#include <string.h><br>#include <errno.h><br><br>#include <PCSC/pcsclite.h><br>#include <PCSC/wintypes.h><br>#include <PCSC/winscard.h><br><br>int main(int argc, char *argv[]){<br>        SCARDCONTEXT hContext;<br>        LONG ret;<br>        int i=1;<br><br>        if(i){<br>                ret=SCardEstablishContext(SCARD_SCOPE_USER, 0, 0, &hContext);<br>                printf("Parent: SCardEstablishCOntext() %s\n", pcsc_stringify_error(ret));<br><br>                SCardReleaseContext(hContext);<br>                printf("released SCard-Context\n");<br>        }<br><br>        // Detach from controlling-terminal<br>        i=fork();<br>        printf("fork()=%d\n",i);<br>        if(i) exit(0);<br><br>        printf("Child\n");<br><br>        ret=SCardEstablishContext(SCARD_SCOPE_USER, 0, 0, &hContext);<br>        printf("Child: SCardEstablishCOntext() %s\n", pcsc_stringify_error(ret));<br><br>        return 0;<br>}<br><br></div>