54pid_t GetDaemonPid(
void)
62 fd = open(PCSCLITE_RUN_PID, O_RDONLY);
65 char pid_ascii[PID_ASCII_SIZE];
68 r = read(fd, pid_ascii,
sizeof pid_ascii);
71 Log2(PCSC_LOG_CRITICAL,
"Reading " PCSCLITE_RUN_PID
" failed: %s",
76 pid = atoi(pid_ascii);
82 Log2(PCSC_LOG_CRITICAL,
"Can't open " PCSCLITE_RUN_PID
": %s",
90int SendHotplugSignal(
void)
98 Log2(PCSC_LOG_INFO,
"Send hotplug signal to pcscd (pid=%ld)",
100 if (kill(pid, SIGUSR1) < 0)
102 Log3(PCSC_LOG_CRITICAL,
"Can't signal pcscd (pid=%ld): %s",
103 (
long)pid, strerror(errno));
104 return EXIT_FAILURE ;
119#define OPENCT_FILE "/var/run/openct/status"
120int CheckForOpenCT(
void)
126 Log1(PCSC_LOG_CRITICAL,
"File " OPENCT_FILE " found. Remove OpenCT and try again");
138long int time_sub(
struct timeval *a,
struct timeval *b)
141 r.tv_sec = a -> tv_sec - b -> tv_sec;
142 r.tv_usec = a -> tv_usec - b -> tv_usec;
146 r.tv_usec += 1000000;
149 return r.tv_sec * 1000000 + r.tv_usec;
153int ThreadCreate(pthread_t * pthThread,
int attributes,
154 PCSCLITE_THREAD_FUNCTION(pvFunction), LPVOID pvArg)
160 ret = pthread_attr_init(&attr);
164 ret = pthread_attr_setdetachstate(&attr,
165 attributes & THREAD_ATTR_DETACHED ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE);
170 ret = pthread_attr_getstacksize(&attr, &stack_size);
176 if ((stack_size != 0) && (stack_size < 0x40000))
178 stack_size = 0x40000;
179 ret = pthread_attr_setstacksize(&attr, stack_size);
184 ret = pthread_create(pthThread, &attr, pvFunction, pvArg);
187 pthread_attr_destroy(&attr);
This handles abstract system level calls.
int SYS_Sleep(int)
Makes the current process sleep for some seconds.
long int time_sub(struct timeval *a, struct timeval *b)
return the difference (as long int) in µs between 2 struct timeval r = a - b
#define OPENCT_FILE
Check is OpenCT is running and display a critical message if it is.