commit 87232e4: [Project] Add child change control command type

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Sep 21 16:21:05 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-21 16:18:27 +0100
URL: https://github.com/rspamd/rspamd/commit/87232e48b7eae8a4cc0ba429d8eecbf6d99e2d3a

[Project] Add child change control command type

---
 src/libserver/rspamd_control.c |  1 +
 src/libserver/rspamd_control.h | 17 +++++++++++++----
 src/libserver/worker_util.c    |  9 +++++++++
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c
index 699317ff5..3d1b8ef7c 100644
--- a/src/libserver/rspamd_control.c
+++ b/src/libserver/rspamd_control.c
@@ -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) {
diff --git a/src/libserver/rspamd_control.h b/src/libserver/rspamd_control.h
index b04fca09d..6c092ca74 100644
--- a/src/libserver/rspamd_control.h
+++ b/src/libserver/rspamd_control.h
@@ -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)
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 58d75da5d..d2e52d5a1 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -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,


More information about the Commits mailing list