utils.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00015 #include <stdio.h>
00016 #include <sys/types.h>
00017 #include <unistd.h>
00018 #include <errno.h>
00019 #include <stdlib.h>
00020 #include <string.h>
00021 #include <signal.h>
00022
00023 #include "debug.h"
00024 #include "config.h"
00025 #include "utils.h"
00026 #include "pcscd.h"
00027
00028 pid_t GetDaemonPid(void)
00029 {
00030 FILE *f;
00031 pid_t pid;
00032
00033
00034
00035
00036 if ((f = fopen(PCSCLITE_RUN_PID, "rb")) != NULL)
00037 {
00038 char pid_ascii[PID_ASCII_SIZE];
00039
00040 fgets(pid_ascii, PID_ASCII_SIZE, f);
00041 fclose(f);
00042
00043 pid = atoi(pid_ascii);
00044 }
00045 else
00046 {
00047 Log2(PCSC_LOG_CRITICAL, "Can't open " PCSCLITE_RUN_PID ": %s",
00048 strerror(errno));
00049 return -1;
00050 }
00051
00052 return pid;
00053 }
00054
00055 int SendHotplugSignal(void)
00056 {
00057 pid_t pid;
00058
00059 pid = GetDaemonPid();
00060
00061 if (pid != -1)
00062 {
00063 Log2(PCSC_LOG_INFO, "Send hotplug signal to pcscd (pid=%d)", pid);
00064 if (kill(pid, SIGUSR1) < 0)
00065 {
00066 Log3(PCSC_LOG_CRITICAL, "Can't signal pcscd (pid=%d): %s",
00067 pid, strerror(errno));
00068 return EXIT_FAILURE ;
00069 }
00070 }
00071
00072 return EXIT_SUCCESS;
00073 }
00074