On Wed, 17 Aug 2016 20:50:25 -0400, Michael Reed wrote:

> Thanks everyone for looking into this, but I'm still experiencing the
> pkg_add issue in snapshots:
> 
>       $ sysctl -n kern.version                                               
>         
>       OpenBSD 6.0-current (GENERIC.MP) #2366: Wed Aug 17 14:05:46 MDT 2016
>           [email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.M
> P
> 
> 
> I should note that the issue now only happens when my pkg.conf contains the f
> ollowing:
> 
>       installpath = http://mirror.jmu.edu/pub/OpenBSD/snapshots/packages/%a/
> 
> When FTP is used, pkg_add seems to cope fine with resizing:
> 
>       installpath = ftp://mirror.jmu.edu/pub/OpenBSD/snapshots/packages/%a/
> 

The http path needs to use connect_sync() too.  The following diff
moves it to util.c and calls it in fetch.c for http.

 - todd

Index: usr.bin/ftp/extern.h
===================================================================
RCS file: /cvs/src/usr.bin/ftp/extern.h,v
retrieving revision 1.42
diff -u -p -u -r1.42 extern.h
--- usr.bin/ftp/extern.h        23 Jan 2014 00:39:15 -0000      1.42
+++ usr.bin/ftp/extern.h        18 Aug 2016 11:09:03 -0000
@@ -62,6 +62,7 @@
  */
 
 #include <sys/types.h>
+#include <sys/socket.h>
 
 void   abort_remote(FILE *);
 void   abortpt(int);
@@ -75,6 +76,7 @@ void  cmdabort(int);
 void   cmdscanner(int);
 int    command(const char *, ...);
 int    confirm(const char *, const char *);
+int    connect_sync(int, const struct sockaddr *, socklen_t);
 FILE   *dataconn(const char *);
 int    foregroundproc(void);
 int    fileindir(const char *, const char *);
Index: usr.bin/ftp/fetch.c
===================================================================
RCS file: /cvs/src/usr.bin/ftp/fetch.c,v
retrieving revision 1.147
diff -u -p -u -r1.147 fetch.c
--- usr.bin/ftp/fetch.c 27 May 2016 15:16:16 -0000      1.147
+++ usr.bin/ftp/fetch.c 18 Aug 2016 11:10:58 -0000
@@ -558,9 +558,7 @@ noslash:
 #endif /* !SMALL */
 
 again:
-               if (connect(s, res->ai_addr, res->ai_addrlen) < 0) {
-                       if (errno == EINTR)
-                               goto again;
+               if (connect_sync(s, res->ai_addr, res->ai_addrlen) < 0) {
                        save_errno = errno;
                        close(s);
                        errno = save_errno;
Index: usr.bin/ftp/ftp.c
===================================================================
RCS file: /cvs/src/usr.bin/ftp/ftp.c,v
retrieving revision 1.97
diff -u -p -u -r1.97 ftp.c
--- usr.bin/ftp/ftp.c   9 Aug 2016 12:09:40 -0000       1.97
+++ usr.bin/ftp/ftp.c   18 Aug 2016 11:09:25 -0000
@@ -108,36 +108,6 @@ off_t      restart_point = 0;
 
 FILE   *cin, *cout;
 
-static int
-connect_sync(int s, const struct sockaddr *name, socklen_t namelen)
-{
-       struct pollfd pfd[1];
-       int error = 0;
-       socklen_t len = sizeof(error);
-
-       if (connect(s, name, namelen) < 0) {
-               if (errno != EINTR)
-                       return -1;
-       }
-
-       /* An interrupted connect(2) continues asyncronously. */
-       pfd[0].fd = s;
-       pfd[0].events = POLLOUT;
-       for (;;) {
-               if (poll(pfd, 1, -1) == -1) {
-                       if (errno != EINTR)
-                               return -1;
-                       continue;
-               }
-               if (getsockopt(s, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
-                       return -1;
-               if (error != 0)
-                       errno = error;
-               break;
-       }
-       return (error ? -1 : 0);
-}
-
 char *
 hookup(char *host, char *port)
 {
Index: usr.bin/ftp/util.c
===================================================================
RCS file: /cvs/src/usr.bin/ftp/util.c,v
retrieving revision 1.79
diff -u -p -u -r1.79 util.c
--- usr.bin/ftp/util.c  14 Aug 2016 18:34:48 -0000      1.79
+++ usr.bin/ftp/util.c  18 Aug 2016 11:11:45 -0000
@@ -76,6 +76,7 @@
 #include <fcntl.h>
 #include <libgen.h>
 #include <glob.h>
+#include <poll.h>
 #include <pwd.h>
 #include <signal.h>
 #include <stdio.h>
@@ -1068,3 +1069,36 @@ controlediting(void)
 }
 #endif /* !SMALL */
 
+/*
+ * Wrapper for connect(2) that restarts the syscall when
+ * interrupted and operates synchronously.
+ */
+int
+connect_sync(int s, const struct sockaddr *name, socklen_t namelen)
+{
+       struct pollfd pfd[1];
+       int error = 0;
+       socklen_t len = sizeof(error);
+
+       if (connect(s, name, namelen) < 0) {
+               if (errno != EINTR)
+                       return -1;
+       }
+
+       /* An interrupted connect(2) continues asyncronously. */
+       pfd[0].fd = s;
+       pfd[0].events = POLLOUT;
+       for (;;) {
+               if (poll(pfd, 1, -1) == -1) {
+                       if (errno != EINTR)
+                               return -1;
+                       continue;
+               }
+               if (getsockopt(s, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
+                       return -1;
+               if (error != 0)
+                       errno = error;
+               break;
+       }
+       return (error ? -1 : 0);
+}

Reply via email to