static gboolean is_insecure = FALSE;
static gboolean gen_keypair = FALSE;
static gboolean encrypt_password = FALSE;
-/* List of workers that are pending to start */
-static GList *workers_pending = NULL;
static GHashTable *ucl_vars = NULL;
static guint term_attempts = 0;
return cur;
}
-static void
-set_alarm (guint seconds)
-{
-#ifdef HAVE_SETITIMER
- static struct itimerval itv;
-
- itv.it_interval.tv_sec = 0;
- itv.it_interval.tv_usec = 0;
- itv.it_value.tv_sec = seconds;
- itv.it_value.tv_usec = 0;
-
- if (setitimer (ITIMER_REAL, &itv, NULL) == -1) {
- msg_err_main ("set alarm failed: %s", strerror (errno));
- }
-#else
- (void)alarm (seconds);
-#endif
-}
-
struct waiting_worker {
+ struct event_base *ev_base;
+ struct event wait_ev;
struct rspamd_worker_conf *cf;
guint oldindex;
};
static void
-delay_fork (struct rspamd_worker_conf *cf, guint index)
+rspamd_fork_delayed_cb (gint signo, short what, gpointer arg)
+{
+ struct waiting_worker *w = arg;
+
+ event_del (&w->wait_ev);
+ fork_worker (rspamd_main, w->cf, w->oldindex);
+ g_slice_free1 (sizeof (*w), w);
+}
+
+static void
+rspamd_fork_delayed (struct rspamd_worker_conf *cf,
+ guint index,
+ struct event_base *ev_base)
{
struct waiting_worker *nw;
+ struct timeval tv;
nw = g_slice_alloc (sizeof (*nw));
nw->cf = cf;
nw->oldindex = index;
-
- workers_pending = g_list_prepend (workers_pending, nw);
- set_alarm (SOFT_FORK_TIME);
+ nw->ev_base = ev_base;
+ tv.tv_sec = SOFT_FORK_TIME;
+ tv.tv_usec = 0;
+ event_set (&nw->wait_ev, -1, EV_TIMEOUT, rspamd_fork_delayed_cb, nw);
+ event_base_set (ev_base, &nw->wait_ev);
+ event_add (&nw->wait_ev, &tv);
}
static GList *
return result;
}
-static void
-fork_delayed (struct rspamd_main *rspamd)
-{
- GList *cur;
- struct waiting_worker *w;
-
- while (workers_pending != NULL) {
- cur = workers_pending;
- w = cur->data;
-
- workers_pending = g_list_remove_link (workers_pending, cur);
- fork_worker (rspamd, w->cf, w->oldindex);
- g_list_free_1 (cur);
- g_slice_free1 (sizeof (*w), w);
- }
-}
-
static inline uintptr_t
make_listen_key (struct rspamd_worker_bind_conf *cf)
{
static void
rspamd_usr1_handler (gint signo, short what, gpointer arg)
{
- struct event_base *ev_base = arg;
-
rspamd_log_reopen_priv (rspamd_main->logger,
rspamd_main->workers_uid,
rspamd_main->workers_gid);
static void
rspamd_hup_handler (gint signo, short what, gpointer arg)
{
- struct event_base *ev_base = arg;
-
rspamd_log_reopen_priv (rspamd_main->logger,
rspamd_main->workers_uid,
rspamd_main->workers_gid);
WEXITSTATUS (res));
}
/* Fork another worker in replace of dead one */
- delay_fork (cur->cf, cur->index);
+ rspamd_fork_delayed (cur->cf, cur->index, ev_base);
}
g_free (cur);
event_base_loop (ev_base, 0);
- /* Set alarm for hard termination */
if (getenv ("G_SLICE") != NULL) {
/* Special case if we are likely running with valgrind */
term_attempts = TERMINATION_ATTEMPTS * 10;
return (res);
}
-
-/*
- * vi:ts=4
- */