]> granicus.if.org Git - neomutt/commitdiff
Block SIGWINCH during connect(). (closes #3941)
authorKevin McCarthy <kevin@8t8.us>
Tue, 20 Jun 2017 22:09:43 +0000 (15:09 -0700)
committerRichard Russon <rich@flatcap.org>
Wed, 28 Jun 2017 14:01:41 +0000 (15:01 +0100)
FreeBSD's connect() does not respect SA_RESTART, so a SIGWINCH will
end up interrupting the connect.

If this code is needed in other places, it should be moved into
signal.c.  For this one place, inlining the sigprocmask() seemed okay.

mutt_socket.c

index 59e4f2050e5c8b519ab4c2966e605c39421c9736..19ef47c4baca42e9f8cf5b6a4db7402e1b7a6656 100644 (file)
@@ -22,6 +22,7 @@
 #include <fcntl.h>
 #include <netdb.h>
 #include <netinet/in.h>
+#include <signal.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/select.h>
@@ -383,6 +384,7 @@ static int socket_connect(int fd, struct sockaddr *sa)
 {
   int sa_size;
   int save_errno;
+  sigset_t set;
 
   if (sa->sa_family == AF_INET)
     sa_size = sizeof(struct sockaddr_in);
@@ -401,6 +403,12 @@ static int socket_connect(int fd, struct sockaddr *sa)
 
   mutt_allow_interrupt(1);
 
+  /* FreeBSD's connect() does not respect SA_RESTART, meaning
+   * a SIGWINCH will cause the connect to fail. */
+  sigemptyset (&set);
+  sigaddset (&set, SIGWINCH);
+  sigprocmask (SIG_BLOCK, &set, NULL);
+
   save_errno = 0;
 
   if (connect(fd, sa, sa_size) < 0)
@@ -413,6 +421,7 @@ static int socket_connect(int fd, struct sockaddr *sa)
   if (ConnectTimeout > 0)
     alarm(0);
   mutt_allow_interrupt(0);
+  sigprocmask (SIG_UNBLOCK, &set, NULL);
 
   return save_errno;
 }