]> granicus.if.org Git - mutt/commitdiff
patch-bac.sockets-20010605.1
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 5 Jun 2001 13:37:08 +0000 (13:37 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 5 Jun 2001 13:37:08 +0000 (13:37 +0000)
imap/command.c
mutt_socket.c
mutt_ssl.c
mutt_tunnel.c

index 55ab7d0620b6346253bcb79cb6dcc7c460190838..39b001d2e5d34782d1168cd3a6e3169d5ced7478 100644 (file)
@@ -235,6 +235,12 @@ int imap_cmd_running (IMAP_DATA* idata)
  *   the index is refreshed, for instance. */
 void imap_cmd_finish (IMAP_DATA* idata)
 {
+  if (idata->status == IMAP_FATAL)
+  {
+    cmd_handle_fatal (idata);
+    return;
+  }
+
   if (!(idata->state == IMAP_SELECTED) || idata->ctx->closing)
     return;
   
@@ -273,13 +279,17 @@ void imap_cmd_finish (IMAP_DATA* idata)
 /* cmd_handle_fatal: when IMAP_DATA is in fatal state, do what we can */
 static void cmd_handle_fatal (IMAP_DATA* idata)
 {
+  idata->status = IMAP_FATAL;
+
   if ((idata->state == IMAP_SELECTED) &&
       (idata->reopen & IMAP_REOPEN_ALLOW) &&
       !idata->ctx->closing)
   {
-    idata->status = 0;
-    idata->state = IMAP_DISCONNECTED;
     mx_fastclose_mailbox (idata->ctx);
+    mutt_error (_("Mailbox closed"));
+    mutt_sleep (1);
+    idata->state = IMAP_DISCONNECTED;
+    idata->status = 0;
   }
 }
 
index 6fc74539432b08fb78f84543d0b0e53133a00b1a..ff1e7f81a4dadfd6db4be464215961db2182fae6 100644 (file)
@@ -155,7 +155,6 @@ int mutt_socket_readln_d (char* buf, size_t buflen, CONNECTION* conn, int dbg)
 {
   char ch;
   int i;
-  int rc;
 
   for (i = 0; i < buflen-1; i++)
   {
@@ -341,9 +340,7 @@ static CONNECTION* socket_new_conn ()
 
 int raw_socket_close (CONNECTION *conn)
 {
-  int ret = close (conn->fd);
-  if (ret == 0) conn->fd = -1;
-  return ret;
+  return close (conn->fd);
 }
 
 int raw_socket_read (CONNECTION* conn, char* buf, size_t len)
index e55d229ccac30899c30b18e6702ee6d778393e9e..aa48ad2fad9f8a4d3b9293b52f0110f7d166417b 100644 (file)
@@ -363,8 +363,6 @@ int ssl_socket_close (CONNECTION * conn)
   return raw_socket_close (conn);
 }
 
-
-
 static char *x509_get_part (char *line, const char *ndx)
 {
   static char ret[SHORT_STRING];
index 1ecb6d093f989844f3aba183d538cf96e8fa3d96..12aadce3a9102b822241e62c62f67d0d0662bdec 100644 (file)
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/wait.h>
+#include <fcntl.h>
+#include <errno.h>
 
 /* -- data types -- */
 typedef struct
 {
   pid_t pid;
+  int readfd;
+  int writefd;
 } TUNNEL_DATA;
 
 /* forward declarations */
 static int tunnel_socket_open (CONNECTION*);
 static int tunnel_socket_close (CONNECTION*);
+static int tunnel_socket_read (CONNECTION* conn, char* buf, size_t len);
+static int tunnel_socket_write (CONNECTION* conn, const char* buf, size_t len);
 
 /* -- public functions -- */
 int mutt_tunnel_socket_setup (CONNECTION *conn)
@@ -45,8 +51,8 @@ int mutt_tunnel_socket_setup (CONNECTION *conn)
   
   conn->open = tunnel_socket_open;
   conn->close = tunnel_socket_close;
-  conn->read = raw_socket_read;
-  conn->write = raw_socket_write;
+  conn->read = tunnel_socket_read;
+  conn->write = tunnel_socket_write;
 
   return 0;
 }
@@ -56,14 +62,18 @@ static int tunnel_socket_open (CONNECTION *conn)
   TUNNEL_DATA* tunnel = (TUNNEL_DATA*) conn->sockdata;
   int pid;
   int rc;
-  int sv[2];
+  int pin[2], pout[2];
 
   mutt_message (_("Connecting with \"%s\"..."), Tunnel);
 
-  rc = socketpair (PF_UNIX, SOCK_STREAM, IPPROTO_IP, sv);
-  if (rc == -1)
+  if ((rc = pipe (pin)) == -1)
+  {
+    mutt_perror ("pipe");
+    return -1;
+  }
+  if ((rc = pipe (pout)) == -1)
   {
-    mutt_perror ("socketpair");
+    mutt_perror ("pipe");
     return -1;
   }
 
@@ -71,12 +81,13 @@ static int tunnel_socket_open (CONNECTION *conn)
   if ((pid = fork ()) == 0)
   {
     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)
+    if (dup2 (pout[0], STDIN_FILENO) < 0 || dup2 (pin[1], STDOUT_FILENO) < 0)
       _exit (127);
+    close (pin[0]);
+    close (pin[1]);
+    close (pout[0]);
+    close (pout[1]);
+    close (STDERR_FILENO);
 
     /* Don't let the subprocess think it can use the controlling tty */
     setsid ();
@@ -88,28 +99,68 @@ static int tunnel_socket_open (CONNECTION *conn)
 
   if (pid == -1)
   {
-    close (sv[0]);
-    close (sv[1]);
+    close (pin[0]);
+    close (pin[1]);
+    close (pout[0]);
+    close (pout[1]);
     mutt_perror ("fork");
     return -1;
   }
-  if (close(sv[1]) < 0)
+  if (close (pin[1]) < 0 || close (pout[0]) < 0)
     mutt_perror ("close");
 
-  conn->fd = sv[0];
+  fcntl (pin[0], F_SETFD, FD_CLOEXEC);
+  fcntl (pout[1], F_SETFD, FD_CLOEXEC);
+
+  tunnel->readfd = pin[0];
+  tunnel->writefd = pout[1];
   tunnel->pid = pid;
 
+  conn->fd = 42; /* stupid hack */
+
   return 0;
 }
 
 static int tunnel_socket_close (CONNECTION* conn)
 {
   TUNNEL_DATA* tunnel = (TUNNEL_DATA*) conn->sockdata;
-  int rc;
 
-  rc = close (conn->fd);
+  close (tunnel->readfd);
+  close (tunnel->writefd);
   waitpid (tunnel->pid, NULL, 0);
   FREE (&conn->sockdata);
 
+  return 0;
+}
+
+static int tunnel_socket_read (CONNECTION* conn, char* buf, size_t len)
+{
+  TUNNEL_DATA* tunnel = (TUNNEL_DATA*) conn->sockdata;
+  int rc;
+
+  rc = read (tunnel->readfd, buf, len);
+  if (rc == -1)
+  {
+    mutt_error (_("Tunnel error talking to %s: %s"), conn->account.host,
+               strerror (errno));
+    mutt_sleep (1);
+  }
+
+  return rc;
+}
+
+static int tunnel_socket_write (CONNECTION* conn, const char* buf, size_t len)
+{
+  TUNNEL_DATA* tunnel = (TUNNEL_DATA*) conn->sockdata;
+  int rc;
+
+  rc = write (tunnel->writefd, buf, len);
+  if (rc == -1)
+  {
+    mutt_error (_("Tunnel error talking to %s: %s"), conn->account.host,
+               strerror (errno));
+    mutt_sleep (1);
+  }
+
   return rc;
 }