summaryrefslogtreecommitdiff
path: root/usr.bin/ftp
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2016-08-18 16:23:07 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2016-08-18 16:23:07 +0000
commit218999672eafee26a871f5ff461adb0d18c87f50 (patch)
tree9a99ae55520b1c5c77b2538787e5ccf606d2396e /usr.bin/ftp
parent7b058fbc2c44ef730c17860c0b218cb5fb1257f9 (diff)
Move connect_sync() to util.c and use it when connecting via http
too. OK sthen@ deraadt@
Diffstat (limited to 'usr.bin/ftp')
-rw-r--r--usr.bin/ftp/extern.h4
-rw-r--r--usr.bin/ftp/fetch.c6
-rw-r--r--usr.bin/ftp/ftp.c32
-rw-r--r--usr.bin/ftp/util.c36
4 files changed, 41 insertions, 37 deletions
diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h
index 8df91d5e6f2..ea894bfe521 100644
--- a/usr.bin/ftp/extern.h
+++ b/usr.bin/ftp/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.42 2014/01/23 00:39:15 deraadt Exp $ */
+/* $OpenBSD: extern.h,v 1.43 2016/08/18 16:23:06 millert Exp $ */
/* $NetBSD: extern.h,v 1.17 1997/08/18 10:20:19 lukem Exp $ */
/*
@@ -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 *);
diff --git a/usr.bin/ftp/fetch.c b/usr.bin/ftp/fetch.c
index 233769ea7d4..41d17c77d96 100644
--- a/usr.bin/ftp/fetch.c
+++ b/usr.bin/ftp/fetch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fetch.c,v 1.147 2016/05/27 15:16:16 jsing Exp $ */
+/* $OpenBSD: fetch.c,v 1.148 2016/08/18 16:23:06 millert Exp $ */
/* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */
/*-
@@ -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;
diff --git a/usr.bin/ftp/ftp.c b/usr.bin/ftp/ftp.c
index 65c624dc293..14f6ea45d3e 100644
--- a/usr.bin/ftp/ftp.c
+++ b/usr.bin/ftp/ftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftp.c,v 1.97 2016/08/09 12:09:40 millert Exp $ */
+/* $OpenBSD: ftp.c,v 1.98 2016/08/18 16:23:06 millert Exp $ */
/* $NetBSD: ftp.c,v 1.27 1997/08/18 10:20:23 lukem Exp $ */
/*
@@ -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)
{
diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c
index a2af0b49971..f0f96ca1bcc 100644
--- a/usr.bin/ftp/util.c
+++ b/usr.bin/ftp/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.79 2016/08/14 18:34:48 guenther Exp $ */
+/* $OpenBSD: util.c,v 1.80 2016/08/18 16:23:06 millert Exp $ */
/* $NetBSD: util.c,v 1.12 1997/08/18 10:20:27 lukem Exp $ */
/*-
@@ -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);
+}