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 
00022 #include "debug.h"
00023 #include "config.h"
00024 #include "utils.h"
00025 
00026 pid_t GetDaemonPid(void)
00027 {
00028     FILE *f;
00029     pid_t pid;
00030 
00031     /* pids are only 15 bits but 4294967296
00032      * (32 bits in case of a new system use it) is on 10 bytes
00033      */
00034     if ((f = fopen(USE_RUN_PID, "rb")) != NULL)
00035     {
00036         char pid_ascii[PID_ASCII_SIZE];
00037 
00038         fgets(pid_ascii, PID_ASCII_SIZE, f);
00039         fclose(f);
00040 
00041         pid = atoi(pid_ascii);
00042     }
00043     else
00044     {
00045         Log2(PCSC_LOG_CRITICAL, "Can't open " USE_RUN_PID ": %s",
00046             strerror(errno));
00047         return -1;
00048     }
00049 
00050     return pid;
00051 } /* GetDaemonPid */
00052 

Generated on Wed Dec 21 12:23:40 2011 for pcsc-lite by  doxygen 1.4.7