Logo Search packages:      
Sourcecode: pcsc-lite version File versions  Download package

LONG SCardCheckDaemonAvailability ( void   )

Checks if the Server is running.

Returns:
Error code.
Return values:
SCARD_S_SUCCESSServer is running (SCARD_S_SUCCESS)
SCARD_E_NO_SERVICEServer is not running (SCARD_E_NO_SERVICE)
SCARD_E_INVALID_HANDLEServer was restarted or after fork() (SCARD_E_INVALID_HANDLE)

Definition at line 3654 of file winscard_clnt.c.

References PCSCLITE_MAX_APPLICATION_CONTEXTS, SCARD_E_INVALID_HANDLE, SCARD_E_NO_SERVICE, SCARD_S_SUCCESS, SCardLockThread(), SCardUnload(), and SCardUnlockThread().

Referenced by SCardBeginTransaction(), SCardCancelTransaction(), SCardConnect(), SCardControl(), SCardDisconnect(), SCardEndTransaction(), SCardEstablishContext(), SCardFreeMemory(), SCardGetStatusChange(), SCardIsValidContext(), SCardListReaderGroups(), SCardListReaders(), SCardReconnect(), SCardReleaseContext(), SCardStatus(), SCardTransmit(), and SHMMessageReceive().

{
      LONG rv;
      struct stat statBuffer;
      int need_restart = 0;

      rv = SYS_Stat(PCSCLITE_PUBSHM_FILE, &statBuffer);

      if (rv != 0)
      {
            Log2(PCSC_LOG_INFO, "PCSC Not Running: " PCSCLITE_PUBSHM_FILE ": %s",
                  strerror(errno));
            return SCARD_E_NO_SERVICE;
      }

      /* when the _first_ reader is connected the ctime changes
       * I don't know why yet */
      if (daemon_ctime && statBuffer.st_ctime > daemon_ctime)
      {
            /* so we also check the daemon pid to be sure it is a new pcscd */
            if (GetDaemonPid() != daemon_pid)
            {
                  Log1(PCSC_LOG_INFO, "PCSC restarted");
                  need_restart = 1;
            }
      }

      /* after fork() need to restart */
      if (client_pid && client_pid != getpid())
      {
            Log1(PCSC_LOG_INFO, "Client forked");
            need_restart = 1;
      }

      if (need_restart)
      {
            int i;

            /* invalid all handles */
            SCardLockThread();

            for (i = 0; i < PCSCLITE_MAX_APPLICATION_CONTEXTS; i++)
                  if (psContextMap[i].hContext)
                        SCardCleanContext(i);

            SCardUnlockThread();

            /* reset pcscd status */
            daemon_ctime = 0;
            client_pid = 0;

            /* reset the lib */
            SCardUnload();

            return SCARD_E_INVALID_HANDLE;
      }

      daemon_ctime = statBuffer.st_ctime;
      daemon_pid = GetDaemonPid();
      client_pid = getpid();

      return SCARD_S_SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index