utils.c

Go to the documentation of this file.
00001 /*
00002  * MUSCLE SmartCard Development ( http://www.linuxnet.com )
00003  *
00004  * Copyright (C) 2006-2007
00005  *  Ludovic Rousseau <ludovic.rousseau@free.fr>
00006  *
00007  * $Id: pcscdaemon.c 2377 2007-02-05 13:13:56Z rousseau $
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     /* pids are only 15 bits but 4294967296
00034      * (32 bits in case of a new system use it) is on 10 bytes
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 } /* GetDaemonPid */
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 } /* SendHotplugSignal */
00074 

Generated on Thu Aug 28 20:14:13 2008 for pcsc-lite by  doxygen 1.5.6