@matheusbsbs / matheus-bagliano / commits / c94d2dd080
Fork 0

imap-send: use run-command API for tunneling

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Erik Faye-Lund committed Oct 19, 2009 at 17:42 UTC c94d2dd0807328b1ee4aa8353382caa45bc24055
1 file changed +16 -21
imap-send.c
+16 -21
@@ -24,6 +24,7 @@
24
25 #include "cache.h"
26 #include "exec_cmd.h"
27 +#include "run-command.h"
28 #ifdef NO_OPENSSL
29 typedef void *SSL;
30 #endif
@@ -940,8 +941,7 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)
941 struct imap_store *ctx;
942 struct imap *imap;
943 char *arg, *rsp;
943 - int s = -1, a[2], preauth;
944 - pid_t pid;
944 + int s = -1, preauth;
945
946 ctx = xcalloc(sizeof(*ctx), 1);
947
@@ -952,29 +952,24 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)
952 /* open connection to IMAP server */
953
954 if (srvc->tunnel) {
955 - imap_info("Starting tunnel '%s'... ", srvc->tunnel);
955 + const char *argv[4];
956 + struct child_process tunnel = {0};
957
957 - if (socketpair(PF_UNIX, SOCK_STREAM, 0, a)) {
958 - perror("socketpair");
959 - exit(1);
960 - }
958 + imap_info("Starting tunnel '%s'... ", srvc->tunnel);
959
962 - pid = fork();
963 - if (pid < 0)
964 - _exit(127);
965 - if (!pid) {
966 - if (dup2(a[0], 0) == -1 || dup2(a[0], 1) == -1)
967 - _exit(127);
968 - close(a[0]);
969 - close(a[1]);
970 - execl("/bin/sh", "sh", "-c", srvc->tunnel, NULL);
971 - _exit(127);
972 - }
960 + argv[0] = "sh";
961 + argv[1] = "-c";
962 + argv[2] = srvc->tunnel;
963 + argv[3] = NULL;
964
974 - close(a[0]);
965 + tunnel.argv = argv;
966 + tunnel.in = -1;
967 + tunnel.out = -1;
968 + if (start_command(&tunnel))
969 + die("cannot start proxy %s", argv[0]);
970
976 - imap->buf.sock.fd[0] = a[1];
977 - imap->buf.sock.fd[1] = dup(a[1]);
971 + imap->buf.sock.fd[0] = tunnel.out;
972 + imap->buf.sock.fd[1] = tunnel.in;
973
974 imap_info("ok\n");
975 } else {