write the correct PID in pid file

This commit is contained in:
Nikos Mavrogiannopoulos
2013-02-12 18:57:05 +01:00
parent e8f6332f36
commit 7270341e62
4 changed files with 13 additions and 11 deletions
+7 -8
View File
@@ -33,7 +33,7 @@
#define DEFAULT_CFG_FILE "/etc/ocserv.conf"
static void write_pid_file(const char* pid_file);
static const char* pid_file = NULL;
static const char* cfg_file = DEFAULT_CFG_FILE;
#define MAX_ENTRIES 64
@@ -102,7 +102,6 @@ static void parse_cfg_file(const char* file, struct cfg_st *config)
{
tOptionValue const * pov;
const tOptionValue* val;
char *pid_file = NULL;
char** auth = NULL;
unsigned auth_size = 0;
unsigned j;
@@ -151,11 +150,8 @@ unsigned j;
READ_STRING("connect-script", config->connect_script, 0);
READ_STRING("disconnect-script", config->disconnect_script, 0);
READ_STRING("pid-file", pid_file, 0);
if (pid_file != NULL) {
write_pid_file(pid_file);
free(pid_file);
}
if (pid_file == NULL)
READ_STRING("pid-file", pid_file, 0);
READ_TF("use-utmp", config->use_utmp, 0, 1);
@@ -301,10 +297,13 @@ unsigned i;
return;
}
static void write_pid_file(const char* pid_file)
void write_pid_file(void)
{
FILE* fp;
if (pid_file==NULL)
return;
fp = fopen(pid_file, "w");
if (fp == NULL) {
fprintf(stderr, "Cannot open pid file '%s'\n", pid_file);