#include "cryptobox.h"
#include "ottery.h"
#include "fuzzy_wire.h"
-#include "libutil/rrd.h"
#include "unix-std.h"
#include "utlist.h"
#include <math.h>
worker);
rspamd_stat_init (worker->srv->cfg, ctx->ev_base);
+ if (worker->index == 0) {
+ rspamd_worker_init_monitored (worker, ctx->ev_base, ctx->resolver);
+ }
+
event_base_loop (ctx->ev_base, 0);
rspamd_worker_block_signals ();
}
+struct event_base *
+rspamd_monitored_ctx_get_ev_base (struct rspamd_monitored_ctx *ctx)
+{
+ return ctx->ev_base;
+}
+
+
struct rspamd_monitored *
rspamd_monitored_create_ (struct rspamd_monitored_ctx *ctx,
const gchar *line,
{
g_assert (m != NULL);
- rspamd_strlcpy (m->tag, tag_out, RSPAMD_MONITORED_TAG_LEN);
+ rspamd_strlcpy (tag_out, m->tag, RSPAMD_MONITORED_TAG_LEN);
}
\ No newline at end of file
mon_change_cb change_cb,
gpointer ud);
+struct event_base *rspamd_monitored_ctx_get_ev_base (struct rspamd_monitored_ctx *ctx);
+
/**
* Create monitored object
* @param ctx context
struct rspamd_worker_session_cache *c = cache;
g_hash_table_remove (c->cache, ptr);
+}
+
+static void
+rspamd_worker_monitored_on_change (struct rspamd_monitored_ctx *ctx,
+ struct rspamd_monitored *m, gboolean alive,
+ void *ud)
+{
+ struct rspamd_worker *worker = ud;
+ struct rspamd_config *cfg = worker->srv->cfg;
+ struct event_base *ev_base;
+ guchar tag[RSPAMD_MONITORED_TAG_LEN];
+ static struct rspamd_srv_command srv_cmd;
+
+ rspamd_monitored_get_tag (m, tag);
+ ev_base = rspamd_monitored_ctx_get_ev_base (ctx);
+ srv_cmd.type = RSPAMD_SRV_MONITORED_CHANGE;
+ rspamd_strlcpy (srv_cmd.cmd.monitored_change.tag, tag,
+ sizeof (srv_cmd.cmd.monitored_change.tag));
+ srv_cmd.cmd.monitored_change.alive = alive;
+ msg_info_config ("broadcast monitored update for %s: %s",
+ srv_cmd.cmd.monitored_change.tag, alive ? "alive" : "dead");
+
+ rspamd_srv_send_command (worker, ev_base, &srv_cmd, -1, NULL, NULL);
+}
+
+void
+rspamd_worker_init_monitored (struct rspamd_worker *worker,
+ struct event_base *ev_base,
+ struct rspamd_dns_resolver *resolver)
+{
+ rspamd_monitored_ctx_config (worker->srv->cfg->monitored_ctx,
+ worker->srv->cfg, ev_base, resolver->r,
+ rspamd_worker_monitored_on_change, worker);
}
\ No newline at end of file
struct rspamd_worker *rspamd_fork_worker (struct rspamd_main *,
struct rspamd_worker_conf *, guint idx, struct event_base *ev_base);
+/**
+ * Initialise the main monitoring worker
+ * @param worker
+ * @param ev_base
+ * @param resolver
+ */
+void rspamd_worker_init_monitored (struct rspamd_worker *worker,
+ struct event_base *ev_base,
+ struct rspamd_dns_resolver *resolver);
+
#define msg_err_main(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
rspamd_main->server_pool->tag.tagname, rspamd_main->server_pool->tag.uid, \
G_STRFUNC, \
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;
memset (&rep, 0, sizeof (rep));
rep.type = RSPAMD_CONTROL_MONITORED_CHANGE;
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,
struct event_base *ev_base,
struct rspamd_dns_resolver *resolver)
{
- rspamd_monitored_ctx_config (worker->srv->cfg->monitored_ctx,
- worker->srv->cfg, ev_base, resolver->r, NULL, NULL);
rspamd_stat_init (worker->srv->cfg, ev_base);
g_ptr_array_add (worker->finish_actions,
(gpointer) rspamd_worker_on_terminate);