From b1160d3fd2e8c2a6f32c12b1f261846384211f41 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Thu, 31 May 2001 18:04:24 +0000 Subject: [PATCH] Tunnel fixes. --- mutt_tunnel.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/mutt_tunnel.c b/mutt_tunnel.c index 4a07b991d..1ecb6d093 100644 --- a/mutt_tunnel.c +++ b/mutt_tunnel.c @@ -39,17 +39,21 @@ static int tunnel_socket_close (CONNECTION*); /* -- public functions -- */ int mutt_tunnel_socket_setup (CONNECTION *conn) { + TUNNEL_DATA* tunnel = (TUNNEL_DATA*) safe_malloc (sizeof (TUNNEL_DATA)); + + conn->sockdata = tunnel; + conn->open = tunnel_socket_open; + conn->close = tunnel_socket_close; conn->read = raw_socket_read; conn->write = raw_socket_write; - conn->close = tunnel_socket_close; return 0; } static int tunnel_socket_open (CONNECTION *conn) { - TUNNEL_DATA* tunnel; + TUNNEL_DATA* tunnel = (TUNNEL_DATA*) conn->sockdata; int pid; int rc; int sv[2]; @@ -63,18 +67,25 @@ static int tunnel_socket_open (CONNECTION *conn) return -1; } + mutt_block_signals_system (); if ((pid = fork ()) == 0) { - mutt_block_signals_system (); + mutt_unblock_signals_system (0); if (close (sv[0]) < 0 || dup2 (sv[1], STDIN_FILENO) < 0 || dup2 (sv[1], STDOUT_FILENO) < 0 || + close (STDERR_FILENO) || close (sv[1]) < 0) _exit (127); + /* Don't let the subprocess think it can use the controlling tty */ + setsid (); + execl (EXECSHELL, "sh", "-c", Tunnel, NULL); _exit (127); } + mutt_unblock_signals_system (1); + if (pid == -1) { close (sv[0]); @@ -86,7 +97,6 @@ static int tunnel_socket_open (CONNECTION *conn) mutt_perror ("close"); conn->fd = sv[0]; - tunnel = (TUNNEL_DATA*) safe_malloc (sizeof (TUNNEL_DATA)); tunnel->pid = pid; return 0; @@ -94,15 +104,12 @@ static int tunnel_socket_open (CONNECTION *conn) static int tunnel_socket_close (CONNECTION* conn) { - TUNNEL_DATA* tunnel = (TUNNEL_DATA*) conn->data; - - if (!tunnel) - return 0; + TUNNEL_DATA* tunnel = (TUNNEL_DATA*) conn->sockdata; + int rc; + rc = close (conn->fd); waitpid (tunnel->pid, NULL, 0); - close (conn->fd); - conn->fd = -1; - FREE (&conn->data); + FREE (&conn->sockdata); - return 0; + return rc; } -- 2.40.0