git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>
Date
Aug 9, 2017, 14:46 UTC
Message-ID
<ac79ae33-db5a-ae90-5e6d-b6364c77266a@morey-chaisemartin.com>
In-Reply-To
<ab866314-608b-eaca-b335-12cffe165526@morey-chaisemartin.com>
Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>
---
 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
Previous: Nicolas Morey-ChaisemartinNext: Nicolas Morey-Chaisemartin
Message 4 of 22 in “[RFC 0/3] imap-send curl tunnelling support”
  1. Nicolas Morey-ChaisemartinAug 9, 2017
  2. 1/3 imap-send: move tunnel setup to its own functionNicolas Morey-Chaisemartin, Aug 9, 2017
  3. 3/3 imap_send: add support for curl over tunnelNicolas Morey-Chaisemartin, Aug 9, 2017
  4. 2/3 imap-send: use a socketpair instead of pipe to communicate with the tunnelNicolas Morey-Chaisemartin, Aug 9, 2017
  5. Nicolas Morey-ChaisemartinAug 15, 2017
  6. Stefan BellerAug 15, 2017
  7. Johannes SchindelinAug 16, 2017
  8. Nicolas Morey-ChaisemartinAug 21, 2017
  9. Johannes SixtAug 22, 2017
  10. Nicolas Morey-ChaisemartinAug 22, 2017
  11. Johannes SchindelinAug 23, 2017
  12. Jeff KingAug 16, 2017
  13. Nicolas Morey-ChaisemartinAug 21, 2017
  14. Jeff KingAug 23, 2017
  15. Nicolas Morey-ChaisemartinAug 24, 2017
  16. Jeff KingAug 24, 2017
  17. Daniel StenbergAug 24, 2017
  18. Jeff KingAug 24, 2017
  19. Daniel StenbergAug 24, 2017
  20. Nicolas Morey-ChaisemartinAug 24, 2017
  21. Jeff KingAug 24, 2017
  22. Jeff KingAug 16, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.