aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver/rspamd_control.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-04 14:24:07 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-04 14:24:07 +0100
commit007c2befbe517ac6d44830a7900c3ac3fdf6d634 (patch)
tree4c4227e2dbbde601fb6a86a7f032e20e5479f59a /src/libserver/rspamd_control.c
parent8857738c6cd2d64dc4a488740946fae64405a47a (diff)
downloadrspamd-007c2befbe517ac6d44830a7900c3ac3fdf6d634.tar.gz
rspamd-007c2befbe517ac6d44830a7900c3ac3fdf6d634.zip
[Feature] Implement log pipe feature for rspamd logs analysis
Diffstat (limited to 'src/libserver/rspamd_control.c')
-rw-r--r--src/libserver/rspamd_control.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c
index 6ed9d1502..cc336174e 100644
--- a/src/libserver/rspamd_control.c
+++ b/src/libserver/rspamd_control.c
@@ -577,6 +577,10 @@ rspamd_control_default_cmd_handler (gint fd,
msg_err ("cannot write reply to the control socket: %s",
strerror (errno));
}
+
+ if (attached_fd != -1) {
+ close (attached_fd);
+ }
}
static void
@@ -698,6 +702,18 @@ rspamd_control_hs_io_handler (gint fd, short what, gpointer ud)
}
static void
+rspamd_control_log_pipe_io_handler (gint fd, short what, gpointer ud)
+{
+ struct rspamd_control_reply_elt *elt = ud;
+ struct rspamd_control_reply rep;
+
+ /* At this point we just ignore replies from the workers */
+ (void) read (fd, &rep, sizeof (rep));
+ event_del (&elt->io_ev);
+ g_slice_free1 (sizeof (*elt), elt);
+}
+
+static void
rspamd_srv_handler (gint fd, short what, gpointer ud)
{
struct rspamd_worker *worker;
@@ -708,7 +724,7 @@ rspamd_srv_handler (gint fd, short what, gpointer ud)
struct cmsghdr *cmsg;
struct iovec iov;
guchar fdspace[CMSG_SPACE(sizeof (int))];
- gint *spair;
+ gint *spair, rfd = -1;
gchar *nid;
struct rspamd_control_command wcmd;
gssize r;
@@ -747,6 +763,9 @@ rspamd_srv_handler (gint fd, short what, gpointer ud)
rdata->rep.id = cmd.id;
rdata->rep.type = cmd.type;
rdata->fd = -1;
+ if (msg.msg_controllen >= CMSG_SPACE(sizeof (int))) {
+ rfd = *(int *) CMSG_DATA(CMSG_FIRSTHDR (&msg));
+ }
switch (cmd.type) {
case RSPAMD_SRV_SOCKETPAIR:
@@ -782,14 +801,24 @@ rspamd_srv_handler (gint fd, short what, gpointer ud)
*/
wcmd.cmd.hs_loaded.cache_dir = cmd.cmd.hs_loaded.cache_dir;
wcmd.cmd.hs_loaded.forced = cmd.cmd.hs_loaded.forced;
- rspamd_control_broadcast_cmd (srv, &wcmd, -1,
+ rspamd_control_broadcast_cmd (srv, &wcmd, rfd,
rspamd_control_hs_io_handler, NULL);
break;
+ case RSPAMD_SRV_LOG_PIPE:
+ memset (&wcmd, 0, sizeof (wcmd));
+ wcmd.cmd.log_pipe.type = cmd.cmd.log_pipe.type;
+ rspamd_control_broadcast_cmd (srv, &wcmd, rfd,
+ rspamd_control_log_pipe_io_handler, NULL);
default:
msg_err ("unknown command type: %d", cmd.type);
break;
}
+ if (rfd != -1) {
+ /* Close our copy to avoid descriptors leak */
+ close (rfd);
+ }
+
/* Now plan write event and send data back */
event_del (&worker->srv_ev);
event_set (&worker->srv_ev,