]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow to attach file descriptors to control commands
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 4 Apr 2016 12:42:36 +0000 (13:42 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 4 Apr 2016 12:42:36 +0000 (13:42 +0100)
src/fuzzy_storage.c
src/hs_helper.c
src/libserver/rspamd_control.c
src/libserver/rspamd_control.h
src/worker.c

index 151a0ba6489da5f402ff833c0750e6515a3ac159..7a603ff5809274c1efa3854900e3339b3bf00c41 100644 (file)
@@ -813,6 +813,7 @@ sync_callback (gint fd, short what, void *arg)
 static gboolean
 rspamd_fuzzy_storage_sync (struct rspamd_main *rspamd_main,
                struct rspamd_worker *worker, gint fd,
+               gint attached_fd,
                struct rspamd_control_command *cmd,
                gpointer ud)
 {
@@ -852,6 +853,7 @@ rspamd_fuzzy_storage_sync (struct rspamd_main *rspamd_main,
 static gboolean
 rspamd_fuzzy_storage_reload (struct rspamd_main *rspamd_main,
                struct rspamd_worker *worker, gint fd,
+               gint attached_fd,
                struct rspamd_control_command *cmd,
                gpointer ud)
 {
@@ -1037,6 +1039,7 @@ rspamd_fuzzy_stat_to_ucl (struct rspamd_fuzzy_storage_ctx *ctx, gboolean ip_stat
 static gboolean
 rspamd_fuzzy_storage_stat (struct rspamd_main *rspamd_main,
                struct rspamd_worker *worker, gint fd,
+               gint attached_fd,
                struct rspamd_control_command *cmd,
                gpointer ud)
 {
index 7e8f7f1c5aac9967e5d679f959fe13bb2c856511..e0c56f4d289ac0ee9edc8a0a80f16334d81c7b17 100644 (file)
@@ -203,6 +203,7 @@ rspamd_rs_compile (struct hs_helper_ctx *ctx, struct rspamd_worker *worker,
 static gboolean
 rspamd_hs_helper_reload (struct rspamd_main *rspamd_main,
                struct rspamd_worker *worker, gint fd,
+               gint attached_fd,
                struct rspamd_control_command *cmd,
                gpointer ud)
 {
index 138809a84c09556cde2b3eec5451f3d5b157eec7..84f68de0216dea9bf2be4598ee226480b01ec2f1 100644 (file)
@@ -491,6 +491,7 @@ struct rspamd_worker_control_data {
 
 static void
 rspamd_control_default_cmd_handler (gint fd,
+               gint attached_fd,
                struct rspamd_worker_control_data *cd,
                struct rspamd_control_command *cmd)
 {
@@ -557,10 +558,21 @@ rspamd_control_default_worker_handler (gint fd, short what, gpointer ud)
 {
        struct rspamd_worker_control_data *cd = ud;
        struct rspamd_control_command cmd;
-
+       struct msghdr msg;
+       struct iovec iov;
+       guchar fdspace[CMSG_SPACE(sizeof (int))];
+       gint rfd = -1;
        gssize r;
 
-       r = read (fd, &cmd, sizeof (cmd));
+       iov.iov_base = &cmd;
+       iov.iov_len = sizeof (cmd);
+       memset (&msg, 0, sizeof (msg));
+       msg.msg_control = fdspace;
+       msg.msg_controllen = sizeof (fdspace);
+       msg.msg_iov = &iov;
+       msg.msg_iovlen = 1;
+
+       r = recvmsg (fd, &msg, 0);
 
        if (r == -1) {
                msg_err ("cannot read request from the control socket: %s",
@@ -582,12 +594,20 @@ rspamd_control_default_worker_handler (gint fd, short what, gpointer ud)
        }
        else if ((gint)cmd.type >= 0 && cmd.type < RSPAMD_CONTROL_MAX) {
 
+               if (msg.msg_controllen >= CMSG_SPACE(sizeof (int))) {
+                       rfd = *(int *) CMSG_DATA(CMSG_FIRSTHDR (&msg));
+               }
+
                if (cd->handlers[cmd.type].handler) {
-                       cd->handlers[cmd.type].handler (cd->worker->srv, cd->worker,
-                                       fd, &cmd, cd->handlers[cmd.type].ud);
+                       cd->handlers[cmd.type].handler (cd->worker->srv,
+                                       cd->worker,
+                                       fd,
+                                       rfd,
+                                       &cmd,
+                                       cd->handlers[cmd.type].ud);
                }
                else {
-                       rspamd_control_default_cmd_handler (fd, cd, &cmd);
+                       rspamd_control_default_cmd_handler (fd, rfd, cd, &cmd);
                }
        }
        else {
index a0d5fba1b968b441486ae4382aceb336bddb6b09..751b916eb81a961398367cac104c7b2a08e44ce4 100644 (file)
@@ -126,11 +126,16 @@ struct rspamd_srv_reply {
                struct {
                        gint forced;
                } hs_loaded;
+               struct {
+                       enum rspamd_log_pipe_type type;
+               } log_pipe;
        } reply;
 };
 
 typedef gboolean (*rspamd_worker_control_handler) (struct rspamd_main *rspamd_main,
-               struct rspamd_worker *worker, gint fd,
+               struct rspamd_worker *worker,
+               gint fd,
+               gint attached_fd,
                struct rspamd_control_command *cmd,
                gpointer ud);
 
index 0e3db7d10ef3e28fdfd5314e18d86f291d332c52..67c262e4038ae76b7dff43c3097d8730988e60d0 100644 (file)
@@ -71,6 +71,12 @@ worker_t normal_worker = {
         G_STRFUNC, \
         __VA_ARGS__)
 
+struct rspamd_worker_log_pipe {
+       gint fd;
+       enum rspamd_log_pipe_type type;
+       struct rspamd_worker_log_pipe *prev, *next;
+};
+
 /*
  * Worker's context
  */
@@ -358,6 +364,7 @@ accept_socket (gint fd, short what, void *arg)
 static gboolean
 rspamd_worker_hyperscan_ready (struct rspamd_main *rspamd_main,
                struct rspamd_worker *worker, gint fd,
+               gint attached_fd,
                struct rspamd_control_command *cmd,
                gpointer ud)
 {