From: Vsevolod Stakhov Date: Thu, 6 Jul 2017 18:36:39 +0000 (+0100) Subject: [Minor] Further fixes to the monitored logic X-Git-Tag: 1.6.2~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e902637bcc1f37a2c7f70c50dad641476056ce8a;p=rspamd.git [Minor] Further fixes to the monitored logic --- diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c index 5d8008415..90dabc4e1 100644 --- a/src/libserver/rspamd_control.c +++ b/src/libserver/rspamd_control.c @@ -823,6 +823,7 @@ rspamd_srv_handler (gint fd, short what, gpointer ud) cmd.cmd.monitored_change.tag, sizeof (wcmd.cmd.monitored_change.tag)); wcmd.cmd.monitored_change.alive = cmd.cmd.monitored_change.alive; + wcmd.cmd.monitored_change.sender = cmd.cmd.monitored_change.sender; rspamd_control_broadcast_cmd (srv, &wcmd, rfd, rspamd_control_hs_io_handler, NULL); break; diff --git a/src/libserver/rspamd_control.h b/src/libserver/rspamd_control.h index fd1395d96..ba26cd187 100644 --- a/src/libserver/rspamd_control.h +++ b/src/libserver/rspamd_control.h @@ -69,6 +69,7 @@ struct rspamd_control_command { struct { gchar tag[32]; gboolean alive; + pid_t sender; } monitored_change; struct { enum rspamd_log_pipe_type type; @@ -138,6 +139,7 @@ struct rspamd_srv_command { struct { gchar tag[32]; gboolean alive; + pid_t sender; } monitored_change; struct { enum rspamd_log_pipe_type type; diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c index 0c0cc9344..1a564786f 100644 --- a/src/libserver/worker_util.c +++ b/src/libserver/worker_util.c @@ -821,6 +821,7 @@ rspamd_worker_monitored_on_change (struct rspamd_monitored_ctx *ctx, rspamd_strlcpy (srv_cmd.cmd.monitored_change.tag, tag, sizeof (srv_cmd.cmd.monitored_change.tag)); srv_cmd.cmd.monitored_change.alive = alive; + srv_cmd.cmd.monitored_change.sender = getpid (); msg_info_config ("broadcast monitored update for %s: %s", srv_cmd.cmd.monitored_change.tag, alive ? "alive" : "dead"); diff --git a/src/worker.c b/src/worker.c index 5c81f419a..3889d0709 100644 --- a/src/worker.c +++ b/src/worker.c @@ -498,23 +498,25 @@ rspamd_worker_monitored_handler (struct rspamd_main *rspamd_main, struct rspamd_control_reply rep; struct rspamd_monitored *m; struct rspamd_monitored_ctx *mctx = worker->srv->cfg->monitored_ctx; - struct rspamd_config *cfg = worker->srv->cfg; + struct rspamd_config *cfg = ud; memset (&rep, 0, sizeof (rep)); rep.type = RSPAMD_CONTROL_MONITORED_CHANGE; - m = rspamd_monitored_by_tag (mctx, cmd->cmd.monitored_change.tag); - - if (!m) { - rspamd_monitored_set_alive (m, cmd->cmd.monitored_change.alive); - rep.reply.monitored_change.status = 1; - msg_info_config ("updated monitored status for %s: %s", - cmd->cmd.monitored_change.tag, - cmd->cmd.monitored_change.alive ? "alive" : "dead"); - } - else { - msg_err ("cannot find monitored by tag: %*s", 32, - cmd->cmd.monitored_change.tag); - rep.reply.monitored_change.status = 0; + + if (cmd->cmd.monitored_change.sender != getpid ()) { + m = rspamd_monitored_by_tag (mctx, cmd->cmd.monitored_change.tag); + + if (m != NULL) { + rspamd_monitored_set_alive (m, cmd->cmd.monitored_change.alive); + rep.reply.monitored_change.status = 1; + msg_info_config ("updated monitored status for %s: %s", + cmd->cmd.monitored_change.tag, + cmd->cmd.monitored_change.alive ? "alive" : "dead"); + } else { + msg_err ("cannot find monitored by tag: %*s", 32, + cmd->cmd.monitored_change.tag); + rep.reply.monitored_change.status = 0; + } } if (write (fd, &rep, sizeof (rep)) != sizeof (rep)) {