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
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
00032
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 }
00052