Added PID file

This commit is contained in:
Nikos Mavrogiannopoulos
2013-02-09 20:06:10 +01:00
parent a5257b6167
commit 8b2ae25e58
5 changed files with 31 additions and 2 deletions

View File

@@ -31,6 +31,8 @@
#include <vpn.h>
static void write_pid_file(const char* pid_file);
#define MAX_ENTRIES 64
#define READ_MULTI_LINE(name, s_name, num, mand) \
@@ -97,6 +99,7 @@ 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;
@@ -143,6 +146,12 @@ 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);
}
READ_TF("use-utmp", config->use_utmp, 0, 1);
@@ -250,3 +259,17 @@ int cmd_parser (int argc, char **argv, struct cfg_st* config)
return 0;
}
static void write_pid_file(const char* pid_file)
{
FILE* fp;
fp = fopen(pid_file, "w");
if (fp == NULL) {
fprintf(stderr, "Cannot open pid file '%s'\n", pid_file);
exit(1);
}
fprintf(fp, "%u", (unsigned)getpid());
fclose(fp);
}

View File

@@ -2,7 +2,7 @@
*
* DO NOT EDIT THIS FILE (ocserv-args.c)
*
* It has been AutoGen-ed February 9, 2013 at 07:49:10 PM by AutoGen 5.16
* It has been AutoGen-ed February 9, 2013 at 08:06:02 PM by AutoGen 5.16
* From the definitions ocserv-args.def
* and the template file options
*

View File

@@ -135,6 +135,9 @@ disconnect-script = /bin/echo
# UTMP
use-utmp = true
# PID file
pid-file = /var/run/ocserv.pid
run-as-user = nobody
run-as-group = nogroup

View File

@@ -2,7 +2,7 @@
*
* DO NOT EDIT THIS FILE (ocserv-args.h)
*
* It has been AutoGen-ed February 9, 2013 at 07:49:10 PM by AutoGen 5.16
* It has been AutoGen-ed February 9, 2013 at 08:06:02 PM by AutoGen 5.16
* From the definitions ocserv-args.def
* and the template file options
*

View File

@@ -7,6 +7,9 @@ auth = "pam"
# UTMP
use-utmp = true
# PID file
pid-file = /var/run/ocserv.pid
# Limit the number of clients. Set to zero for unlimited.
# max-clients = 1024
max-clients = 4