From: Vsevolod Stakhov Date: Mon, 4 Apr 2016 17:20:48 +0000 (+0100) Subject: [Minor] Add startup mutex X-Git-Tag: 1.2.3~64 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=37b5f80e6e23639d9deb10707585e3751182784b;p=rspamd.git [Minor] Add startup mutex --- diff --git a/src/log_helper.c b/src/log_helper.c index 63e824420..b1a241288 100644 --- a/src/log_helper.c +++ b/src/log_helper.c @@ -144,8 +144,11 @@ start_log_helper (struct rspamd_worker *worker) srv_cmd.type = RSPAMD_SRV_LOG_PIPE; srv_cmd.cmd.log_pipe.type = RSPAMD_LOG_PIPE_SYMBOLS; + /* Wait for startup being completed */ + rspamd_mempool_lock_mutex (worker->srv->start_mtx); rspamd_srv_send_command (worker, ctx->ev_base, &srv_cmd, ctx->pair[1], rspamd_log_helper_reply_handler, ctx); + rspamd_mempool_unlock_mutex (worker->srv->start_mtx); event_base_loop (ctx->ev_base, 0); close (ctx->pair[0]); rspamd_worker_block_signals (); diff --git a/src/rspamd.c b/src/rspamd.c index 73be189c7..f6785fa99 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -994,6 +994,7 @@ main (gint argc, gchar **argv, gchar **env) rspamd_main->cfg = rspamd_config_new (); rspamd_main->spairs = g_hash_table_new_full (rspamd_spair_hash, rspamd_spair_equal, g_free, rspamd_spair_close); + rspamd_main->start_mtx = rspamd_mempool_get_mutex (rspamd_main->server_pool); #ifndef HAVE_SETPROCTITLE init_title (argc, argv, env); @@ -1232,7 +1233,9 @@ main (gint argc, gchar **argv, gchar **env) event_add (&usr1_ev, NULL); rspamd_check_core_limits (rspamd_main); + rspamd_mempool_lock_mutex (rspamd_main->start_mtx); spawn_workers (rspamd_main, ev_base); + rspamd_mempool_unlock_mutex (rspamd_main->start_mtx); if (control_fd != -1) { msg_info_main ("listening for control commands on %s", @@ -1291,6 +1294,7 @@ main (gint argc, gchar **argv, gchar **env) 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); g_free (rspamd_main); event_base_free (ev_base); diff --git a/src/rspamd.h b/src/rspamd.h index 286a929f8..a677f02c7 100644 --- a/src/rspamd.h +++ b/src/rspamd.h @@ -235,6 +235,7 @@ struct rspamd_main { struct rspamd_stat *stat; /**< pointer to statistics */ rspamd_mempool_t *server_pool; /**< server's memory pool */ + rspamd_mempool_mutex_t *start_mtx; /**< server is starting up */ GHashTable *workers; /**< workers pool indexed by pid */ GHashTable *spairs; /**< socket pairs requested by workers */ rspamd_logger_t *logger;