write the correct PID in pid file

This commit is contained in:
Nikos Mavrogiannopoulos
2013-02-12 18:54:15 +01:00
parent e8f6332f36
commit 7270341e62
4 changed files with 13 additions and 11 deletions

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);
if (pid_file == NULL)
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);
@@ -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);

View File

@@ -463,7 +463,6 @@ int connected = 0;
fail:
if (connected == 0) {
/* received packet from unknown host */
// mslog(s, NULL, LOG_ERR, "Received UDP packet from unexpected host; discarding it");
recv(listener->fd, buffer, buffer_size, 0);
return -1;
@@ -473,6 +472,8 @@ fail:
}
#define MAINTAINANCE_TIME (config.cookie_validity + 300)
int main(int argc, char** argv)
{
int fd, pid, e;
@@ -541,7 +542,8 @@ int main(int argc, char** argv)
if (config.foreground == 0)
daemon(0, 0);
#define MAINTAINANCE_TIME (config.cookie_validity + 300)
write_pid_file();
alarm(MAINTAINANCE_TIME);
flags = LOG_PID|LOG_NDELAY;
#ifdef LOG_PERROR

View File

@@ -11,6 +11,7 @@
int cmd_parser (int argc, char **argv, struct cfg_st* config);
void reload_cfg_file(struct cfg_st* config);
void write_pid_file(void);
struct listener_st {
struct list_node list;

View File

@@ -371,9 +371,9 @@ const char* perr;
int tls_global_init_client(worker_st* ws)
{
#ifdef HAVE_PKCS11
int ret;
#ifdef HAVE_PKCS11
/* when we have PKCS #11 keys we cannot open them and then fork(), we need
* to open them at the process they are going to be used. */
if (ws->config->key != NULL && strncmp(ws->config->key, "pkcs11:", 7) == 0) {