summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-14 14:21:54 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-14 14:21:54 +0000
commit4f706158bcc0318dc79d7a81ebf1553a8a43b624 (patch)
tree6409548e38b30a73addc5d917cdf4edf1f3caa3c /src
parent7055b8410da2bbb1bf06d6a276ba91b45f6f3a08 (diff)
downloadrspamd-4f706158bcc0318dc79d7a81ebf1553a8a43b624.tar.gz
rspamd-4f706158bcc0318dc79d7a81ebf1553a8a43b624.zip
Allow fd attaching to control replies
Diffstat (limited to 'src')
-rw-r--r--src/libserver/rspamd_control.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c
index 8b85c745a..d1eed7d24 100644
--- a/src/libserver/rspamd_control.c
+++ b/src/libserver/rspamd_control.c
@@ -49,6 +49,7 @@ struct rspamd_control_reply_elt {
struct event io_ev;
struct rspamd_worker *wrk;
gpointer ud;
+ gint attached_fd;
struct rspamd_control_reply_elt *prev, *next;
};
@@ -244,14 +245,32 @@ rspamd_control_wrk_io (gint fd, short what, gpointer ud)
{
struct rspamd_control_reply_elt *elt = ud;
struct rspamd_control_session *session;
+ guchar fdspace[CMSG_SPACE(sizeof (int))];
+ struct iovec iov;
+ struct msghdr msg;
+ gssize r;
session = elt->ud;
-
- if (read (elt->wrk->control_pipe[0], &elt->reply, sizeof (elt->reply)) !=
- sizeof (elt->reply)) {
+ elt->attached_fd = -1;
+
+ iov.iov_base = &elt->reply;
+ iov.iov_len = sizeof (elt->reply);
+ 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 worker %P (%s): %s",
elt->wrk->pid, g_quark_to_string (elt->wrk->type), strerror (errno));
}
+ else if (r >= (gssize)sizeof (elt->reply)) {
+ if (msg.msg_controllen >= CMSG_SPACE(sizeof (int))) {
+ elt->attached_fd = *(int *) CMSG_DATA(CMSG_FIRSTHDR (&msg));
+ }
+ }
session->replies_remain --;
event_del (&elt->io_ev);