[RFC 2/3] imap-send: use a socketpair instead of pipe to communicate with the tunnel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@xxxxxxxxxxxxxxxxxxxxxx>
---
 imap-send.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/imap-send.c b/imap-send.c
index 10f668eb7..e5ff70096 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -929,18 +929,27 @@ static int auth_cram_md5(struct imap_store *ctx, struct imap_cmd *cmd, const cha
 static void setup_tunnel(struct imap_server_conf *srvc, int fds[2])
 {
 	struct child_process tunnel = CHILD_PROCESS_INIT;
+	int sock_fds[2];
 
 	imap_info("Starting tunnel '%s'... ", srvc->tunnel);
 
+	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock_fds))
+		die("failed to create socketpair for proxy");
+
 	argv_array_push(&tunnel.args, srvc->tunnel);
 	tunnel.use_shell = 1;
-	tunnel.in = -1;
-	tunnel.out = -1;
+	tunnel.in = sock_fds[1];
+	/* Duplicate the fd as the child process requires
+	 * 1 for stdin, one for stdout */
+	tunnel.out = dup(sock_fds[1]);
+	if (tunnel.out < 0)
+		die("failed to create fd to proxy");
+
 	if (start_command(&tunnel))
 		die("cannot start proxy %s", srvc->tunnel);
 
-	fds[0] = tunnel.out;
-	fds[1] = tunnel.in;
+	fds[0] = sock_fds[0];
+	fds[1] = sock_fds[0];
 
 	imap_info("ok\n");
 
-- 
2.14.0.3.gb4ff627ec.dirty





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux