]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Add child change control command type
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 21 Sep 2019 15:18:27 +0000 (16:18 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 21 Sep 2019 15:18:27 +0000 (16:18 +0100)
src/libserver/rspamd_control.c
src/libserver/rspamd_control.h
src/libserver/worker_util.c

index 699317ff51b5e66e2eabd8cfc72dae80c3eb4d44..3d1b8ef7ca31c7a042758170d5fca88e04a4d757 100644 (file)
@@ -597,6 +597,7 @@ rspamd_control_default_cmd_handler (gint fd,
        case RSPAMD_CONTROL_FUZZY_STAT:
        case RSPAMD_CONTROL_FUZZY_SYNC:
        case RSPAMD_CONTROL_LOG_PIPE:
+       case RSPAMD_CONTROL_CHILD_CHANGE:
                break;
        case RSPAMD_CONTROL_RERESOLVE:
                if (cd->worker->srv->cfg) {
index b04fca09d466b4b75d43686755dc320ccde2274a..6c092ca74ec2ef750bb1d9988050e6ad344376f6 100644 (file)
@@ -37,6 +37,7 @@ enum rspamd_control_type {
        RSPAMD_CONTROL_FUZZY_STAT,
        RSPAMD_CONTROL_FUZZY_SYNC,
        RSPAMD_CONTROL_MONITORED_CHANGE,
+       RSPAMD_CONTROL_CHILD_CHANGE,
        RSPAMD_CONTROL_MAX
 };
 
@@ -86,6 +87,15 @@ struct rspamd_control_command {
                struct {
                        guint unused;
                } fuzzy_sync;
+               struct {
+                       enum {
+                               rspamd_child_offline,
+                               rspamd_child_online,
+                               rspamd_child_terminated,
+                       } what;
+                       pid_t pid;
+                       guint additional;
+               } child_change;
        } cmd;
 };
 
@@ -246,10 +256,9 @@ void rspamd_srv_send_command (struct rspamd_worker *worker,
  * @param cmd
  * @param except_pid
  */
-void
-rspamd_control_broadcast_srv_cmd (struct rspamd_main *rspamd_main,
-                                                                 struct rspamd_control_command *cmd,
-                                                                 pid_t except_pid);
+void rspamd_control_broadcast_srv_cmd (struct rspamd_main *rspamd_main,
+                                                                          struct rspamd_control_command *cmd,
+                                                                          pid_t except_pid);
 
 /**
  * Returns command from a specified string (case insensitive)
index 58d75da5d706c0454307317f901f4c1f48486599..d2e52d5a1c3207cf6f0f90871ad2d810e1b9db8a 100644 (file)
@@ -714,6 +714,7 @@ rspamd_main_heartbeat_cb (EV_P_ ev_timer *w, int revents)
        struct rspamd_worker *wrk = (struct rspamd_worker *)w->data;
        gdouble time_from_last = ev_time ();
        struct rspamd_main *rspamd_main;
+       static struct rspamd_control_command cmd;
        struct tm tm;
        gchar timebuf[64];
        gchar usec_buf[16];
@@ -735,6 +736,10 @@ rspamd_main_heartbeat_cb (EV_P_ ev_timer *w, int revents)
 
                if (wrk->hb.nbeats > 0) {
                        /* First time lost event */
+                       cmd.type = RSPAMD_CONTROL_CHILD_CHANGE;
+                       cmd.cmd.child_change.what = rspamd_child_offline;
+                       cmd.cmd.child_change.pid = wrk->pid;
+                       rspamd_control_broadcast_srv_cmd (rspamd_main, &cmd, wrk->pid);
                        msg_warn_main ("lost heartbeat from worker type %s with pid %P, "
                                  "last beat on: %s (%L beats received previously)",
                                        g_quark_to_string (wrk->type), wrk->pid,
@@ -761,6 +766,10 @@ rspamd_main_heartbeat_cb (EV_P_ ev_timer *w, int revents)
                rspamd_snprintf (timebuf + r, sizeof (timebuf) - r,
                                "%s", usec_buf + 1);
 
+               cmd.type = RSPAMD_CONTROL_CHILD_CHANGE;
+               cmd.cmd.child_change.what = rspamd_child_online;
+               cmd.cmd.child_change.pid = wrk->pid;
+               rspamd_control_broadcast_srv_cmd (rspamd_main, &cmd, wrk->pid);
                msg_info_main ("received heartbeat from worker type %s with pid %P, "
                                           "last beat on: %s (%L beats lost previously)",
                                g_quark_to_string (wrk->type), wrk->pid,