On Mon, 8 Aug 2016, Todd C. Miller wrote:
> POSIX says connect(2) does not restart so we need to do the same kind of 
> dance as async connect(2).

Untested, but the obvious port from the other BSDs to have connect() leave 
the connect running asynchronously.

Philip

Index: uipc_syscalls.c
===================================================================
RCS file: /data/src/openbsd/src/sys/kern/uipc_syscalls.c,v
retrieving revision 1.132
diff -u -p -r1.132 uipc_syscalls.c
--- uipc_syscalls.c     18 May 2016 01:13:13 -0000      1.132
+++ uipc_syscalls.c     8 Aug 2016 20:09:12 -0000
@@ -367,7 +367,7 @@ sys_connect(struct proc *p, void *v, reg
        struct file *fp;
        struct socket *so;
        struct mbuf *nam = NULL;
-       int error, s;
+       int error, s, interrupted = 0;
 
        if ((error = getsock(p, SCARG(uap, s), &fp)) != 0)
                return (error);
@@ -409,8 +409,11 @@ sys_connect(struct proc *p, void *v, reg
        s = splsoftnet();
        while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
                error = tsleep(&so->so_timeo, PSOCK | PCATCH, "netcon2", 0);
-               if (error)
+               if (error) {
+                       if (error == EINTR || error == ERESTART)
+                               interrupted = 1;
                        break;
+               }
        }
        if (error == 0) {
                error = so->so_error;
@@ -418,7 +421,8 @@ sys_connect(struct proc *p, void *v, reg
        }
        splx(s);
 bad:
-       so->so_state &= ~SS_ISCONNECTING;
+       if (!interrupted)
+               so->so_state &= ~SS_ISCONNECTING;
        FRELE(fp, p);
        if (nam)
                m_freem(nam);

Reply via email to