From: Vsevolod Stakhov Date: Mon, 14 Dec 2015 14:21:54 +0000 (+0000) Subject: Allow fd attaching to control replies X-Git-Tag: 1.1.0~312 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4f706158bcc0318dc79d7a81ebf1553a8a43b624;p=rspamd.git Allow fd attaching to control replies --- 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);