fd = open (ctx->saved_stats_path, O_WRONLY|O_CREAT|O_TRUNC, 00644);
if (fd == -1) {
- msg_err_ctx ("cannot load controller stats from %s: %s",
+ msg_err_ctx ("cannot open for writing controller stats from %s: %s",
ctx->saved_stats_path, strerror (errno));
return;
}
if (rspamd_file_lock (fd, FALSE) == -1) {
- msg_err_ctx ("cannot load controller stats from %s: %s",
+ msg_err_ctx ("cannot lock controller stats in %s: %s",
ctx->saved_stats_path, strerror (errno));
close (fd);
return ctx;
}
+static void
+rspamd_controller_on_terminate (struct rspamd_worker *worker)
+{
+ struct rspamd_controller_worker_ctx *ctx = worker->ctx;
+
+ rspamd_controller_store_saved_stats (ctx);
+
+ if (ctx->rrd) {
+ event_del (ctx->rrd_event);
+ rspamd_rrd_close (ctx->rrd);
+ }
+}
+
/*
* Start worker process
*/
DEFAULT_STATS_PATH);
}
+ g_ptr_array_add (worker->finish_actions,
+ (gpointer)rspamd_controller_on_terminate);
rspamd_controller_load_saved_stats (ctx);
/* RRD collector */
rspamd_stat_close ();
rspamd_http_router_free (ctx->http);
rspamd_log_close (worker->srv->logger);
- rspamd_controller_store_saved_stats (ctx);
-
- if (ctx->rrd) {
- rspamd_rrd_close (ctx->rrd);
- }
if (ctx->cached_password.len > 0) {
m = (gpointer)ctx->cached_password.begin;
sig_atomic_t wanna_die = 0;
+static void
+rspamd_worker_terminate_handlers (struct rspamd_worker *w)
+{
+ guint i;
+ void (*cb)(struct rspamd_worker *);
+
+ for (i = 0; i < w->finish_actions->len; i ++) {
+ cb = g_ptr_array_index (w->finish_actions, i);
+ cb (w);
+ }
+}
/*
* Config reload is designed by sending sigusr2 to active workers and pending shutdown of them
*/
tv.tv_sec = SOFT_SHUTDOWN_TIME;
tv.tv_usec = 0;
wanna_die = 1;
+ rspamd_worker_terminate_handlers (sigh->worker);
rspamd_default_log_function (G_LOG_LEVEL_INFO,
sigh->worker->srv->server_pool->tag.tagname,
sigh->worker->srv->server_pool->tag.uid,
G_STRFUNC,
"terminating after receiving signal %s",
g_strsignal (sigh->signo));
+ rspamd_worker_terminate_handlers (sigh->worker);
wanna_die = 1;
tv.tv_sec = 0;
tv.tv_usec = 0;
memcpy (wrk->cf, cf, sizeof (struct rspamd_worker_conf));
wrk->index = index;
wrk->ctx = cf->ctx;
+ wrk->finish_actions = g_ptr_array_new ();
wrk->pid = fork ();
g_quark_to_string (w->type), w->pid,
WTERMSIG (res) == SIGKILL ? "hardly" : "softly");
event_del (&w->srv_ev);
+ g_ptr_array_free (w->finish_actions, TRUE);
g_free (w->cf);
g_free (w);
main process. [0] - main, [1] - worker */
struct event srv_ev; /**< used by main for read workers' requests */
gpointer control_data; /**< used by control protocol to handle commands */
+ GPtrArray *finish_actions; /**< called when worker is terminated */
};
struct rspamd_abstract_worker_ctx {