diff options
-rw-r--r-- | src/libserver/worker_util.c | 12 | ||||
-rw-r--r-- | src/rspamd.c | 15 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c index 8b4ca4027..d2cca5b68 100644 --- a/src/libserver/worker_util.c +++ b/src/libserver/worker_util.c @@ -629,7 +629,11 @@ rspamd_fork_worker (struct rspamd_main *rspamd_main, setrlimit (RLIMIT_STACK, &rlim); setproctitle ("%s process", cf->worker->name); - rspamd_pidfile_close (rspamd_main->pfh); + + if (rspamd_main->pfh) { + rspamd_pidfile_close (rspamd_main->pfh); + } + /* Do silent log reopen to avoid collisions */ rspamd_log_close (rspamd_main->logger); rspamd_log_open (rspamd_main->logger); @@ -658,7 +662,11 @@ rspamd_fork_worker (struct rspamd_main *rspamd_main, break; case -1: msg_err_main ("cannot fork main process. %s", strerror (errno)); - rspamd_pidfile_remove (rspamd_main->pfh); + + if (rspamd_main->pfh) { + rspamd_pidfile_remove (rspamd_main->pfh); + } + rspamd_hard_terminate (rspamd_main); break; default: diff --git a/src/rspamd.c b/src/rspamd.c index a44f33b6c..abc15ead9 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -1162,6 +1162,7 @@ main (gint argc, gchar **argv, gchar **env) struct event term_ev, int_ev, cld_ev, hup_ev, usr1_ev, control_ev; struct timeval term_tv; struct rspamd_main *rspamd_main; + gboolean skip_pid = FALSE; #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30)) g_thread_init (NULL); @@ -1348,7 +1349,12 @@ main (gint argc, gchar **argv, gchar **env) sigaction (SIGPIPE, &sigpipe_act, NULL); if (rspamd_main->cfg->pid_file == NULL) { - msg_info("pid file is not specified, skipping writing it"); + msg_info_main ("pid file is not specified, skipping writing it"); + skip_pid = TRUE; + } + else if (no_fork) { + msg_info_main ("skip writing pid in no-fork mode"); + skip_pid = TRUE; } else if (rspamd_write_pid (rspamd_main) == -1) { msg_err_main ("cannot write pid file %s", rspamd_main->cfg->pid_file); @@ -1479,11 +1485,16 @@ main (gint argc, gchar **argv, gchar **env) } msg_info_main ("terminating..."); + rspamd_log_close (rspamd_main->logger); REF_RELEASE (rspamd_main->cfg); g_hash_table_unref (rspamd_main->spairs); rspamd_mempool_delete (rspamd_main->server_pool); - rspamd_pidfile_close (rspamd_main->pfh); + + if (!skip_pid) { + rspamd_pidfile_close (rspamd_main->pfh); + } + g_free (rspamd_main); event_base_free (ev_base); |