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

[PATCH/RFC 2/7] imap-send: use run-command API for tunneling

From
Erik Faye-Lund <kusmabite@googlemail.com>
Date
Oct 3, 2009, 00:39 UTC
Message-ID
<1254530385-2824-2-git-send-email-kusmabite@gmail.com>
In-Reply-To
<1254530385-2824-1-git-send-email-kusmabite@gmail.com>
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---
 imap-send.c |   37 ++++++++++++++++---------------------
 1 files changed, 16 insertions(+), 21 deletions(-)
diff --git a/imap-send.c b/imap-send.c
index ba50961..55a663a 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -24,6 +24,7 @@
 
 #include "cache.h"
 #include "exec_cmd.h"
+#include "run-command.h"
 #ifdef NO_OPENSSL
 typedef void *SSL;
 #endif
@@ -989,8 +990,7 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)
 	struct imap_store *ctx;
 	struct imap *imap;
 	char *arg, *rsp;
-	int s = -1, a[2], preauth;
-	pid_t pid;
+	int s = -1, preauth;
 
 	ctx = xcalloc(sizeof(*ctx), 1);
 
@@ -1001,29 +1001,24 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)
 	/* open connection to IMAP server */
 
 	if (srvc->tunnel) {
-		imap_info("Starting tunnel '%s'... ", srvc->tunnel);
+		const char *argv[4];
+		struct child_process tunnel = {0};
 
-		if (socketpair(PF_UNIX, SOCK_STREAM, 0, a)) {
-			perror("socketpair");
-			exit(1);
-		}
+		imap_info("Starting tunnel '%s'... ", srvc->tunnel);
 
-		pid = fork();
-		if (pid < 0)
-			_exit(127);
-		if (!pid) {
-			if (dup2(a[0], 0) == -1 || dup2(a[0], 1) == -1)
-				_exit(127);
-			close(a[0]);
-			close(a[1]);
-			execl("/bin/sh", "sh", "-c", srvc->tunnel, NULL);
-			_exit(127);
-		}
+		argv[0] = "/bin/sh";
+		argv[1] = "-c";
+		argv[2] = srvc->tunnel;
+		argv[3] = NULL;
 
-		close(a[0]);
+		tunnel.argv = argv;
+		tunnel.in = -1;
+		tunnel.out = -1;
+		if (start_command(&tunnel))
+			die("cannot start proxy %s", argv[0]);
 
-		imap->buf.sock.fd[0] = a[1];
-		imap->buf.sock.fd[1] = dup(a[1]);
+		imap->buf.sock.fd[0] = tunnel.out;
+		imap->buf.sock.fd[1] = tunnel.in;
 
 		imap_info("ok\n");
 	} else {
-- 
1.6.5.rc2.7.g4f8d3
Previous: Erik Faye-LundNext: Erik Faye-Lund
Message 2 of 18 in “imap-send: use separate read and write fds”
  1. 1/7 imap-send: use separate read and write fdsErik Faye-Lund, Oct 3, 2009
  2. 2/7 imap-send: use run-command API for tunnelingErik Faye-Lund, Oct 3, 2009
  3. 3/7 imap-send: fix compilation-error on WindowsErik Faye-Lund, Oct 3, 2009
  4. 4/7 imap-send: build imap-send on WindowsErik Faye-Lund, Oct 3, 2009
  5. 5/7 imap-send: provide fall-back random-sourceErik Faye-Lund, Oct 3, 2009
  6. 6/7 mingw: wrap SSL_set_(w|r)fd to call _get_osfhandleErik Faye-Lund, Oct 3, 2009
  7. 7/7 mingw: enable OpenSSLErik Faye-Lund, Oct 3, 2009
  8. Jeff KingOct 3, 2009
  9. Erik Faye-LundOct 3, 2009
  10. Erik Faye-LundOct 3, 2009
  11. Jeff KingOct 3, 2009
  12. Jeff KingOct 3, 2009
  13. Erik Faye-LundOct 8, 2009
  14. Jeff KingOct 9, 2009
  15. Jeff KingOct 3, 2009
  16. Erik Faye-LundOct 3, 2009
  17. Jeff KingOct 3, 2009
  18. Johannes SixtOct 3, 2009

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.