diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-15 09:38:47 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-09-15 09:38:47 +0100 |
commit | 0844254be5130d633dbd1357cf50f433aee5eb78 (patch) | |
tree | 800f63bbef7c8448e5489a1261cb63bf71457dad /src/libserver/rspamd_control.c | |
parent | 0929b6e73efdc3fd56318d5d35bd39ef08e0b9f4 (diff) | |
download | rspamd-0844254be5130d633dbd1357cf50f433aee5eb78.tar.gz rspamd-0844254be5130d633dbd1357cf50f433aee5eb78.zip |
[Project] Avoid using of the worker pointer in srv handlers
Diffstat (limited to 'src/libserver/rspamd_control.c')
-rw-r--r-- | src/libserver/rspamd_control.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c index 4ca3d6585..2e6ad21f0 100644 --- a/src/libserver/rspamd_control.c +++ b/src/libserver/rspamd_control.c @@ -36,7 +36,8 @@ struct rspamd_control_reply_elt { struct rspamd_control_reply reply; struct rspamd_io_ev ev; struct ev_loop *event_loop; - struct rspamd_worker *wrk; + GQuark wrk_type; + pid_t wrk_pid; gpointer ud; gint attached_fd; struct rspamd_control_reply_elt *prev, *next; @@ -193,15 +194,15 @@ rspamd_control_write_reply (struct rspamd_control_session *session) /* Skip incompatible worker for fuzzy_stat */ if ((session->cmd.type == RSPAMD_CONTROL_FUZZY_STAT || session->cmd.type == RSPAMD_CONTROL_FUZZY_SYNC) && - elt->wrk->type != g_quark_from_static_string ("fuzzy")) { + elt->wrk_type != g_quark_from_static_string ("fuzzy")) { continue; } - rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "%P", elt->wrk->pid); + rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "%P", elt->wrk_pid); cur = ucl_object_typed_new (UCL_OBJECT); ucl_object_insert_key (cur, ucl_object_fromstring (g_quark_to_string ( - elt->wrk->type)), "type", 0, false); + elt->wrk_type)), "type", 0, false); switch (session->cmd.type) { case RSPAMD_CONTROL_STAT: @@ -340,7 +341,7 @@ rspamd_control_wrk_io (gint fd, short what, gpointer ud) r = recvmsg (fd, &msg, 0); if (r == -1) { msg_err ("cannot read reply from the worker %P (%s): %s", - elt->wrk->pid, g_quark_to_string (elt->wrk->type), + elt->wrk_pid, g_quark_to_string (elt->wrk_type), strerror (errno)); } else if (r >= (gssize)sizeof (elt->reply)) { @@ -352,7 +353,7 @@ rspamd_control_wrk_io (gint fd, short what, gpointer ud) else { /* Timeout waiting */ msg_warn ("timeout waiting reply from %P (%s)", - elt->wrk->pid, g_quark_to_string (elt->wrk->type)); + elt->wrk_pid, g_quark_to_string (elt->wrk_type)); } session->replies_remain --; @@ -384,9 +385,10 @@ rspamd_control_error_handler (struct rspamd_http_connection *conn, GError *err) static struct rspamd_control_reply_elt * rspamd_control_broadcast_cmd (struct rspamd_main *rspamd_main, - struct rspamd_control_command *cmd, - gint attached_fd, - void (*handler) (int, short, void *), gpointer ud) + struct rspamd_control_command *cmd, + gint attached_fd, + rspamd_ev_cb handler, + gpointer ud) { GHashTableIter it; struct rspamd_worker *wrk; @@ -430,7 +432,8 @@ rspamd_control_broadcast_cmd (struct rspamd_main *rspamd_main, if (r == sizeof (*cmd)) { rep_elt = g_malloc0 (sizeof (*rep_elt)); - rep_elt->wrk = wrk; + rep_elt->wrk_pid = wrk->pid; + rep_elt->wrk_type = wrk->type; rep_elt->event_loop = rspamd_main->event_loop; rep_elt->ud = ud; rspamd_ev_watcher_init (&rep_elt->ev, |