Module Name: src
Committed By: lukem
Date: Sat Dec 10 05:53:59 UTC 2011
Modified Files:
src/usr.bin/ftp: fetch.c ftp.c main.c util.c
Log Message:
Move determination of socket buffer sizes from startup to the first
time a socket is used, as the previous logic assumed AF_INET sockets
were available (which they may not be in an IPv6-only system).
Per discussion with Maxim Konovalov and the FreeBSD problem 162661.
To generate a diff of this commit:
cvs rdiff -u -r1.194 -r1.195 src/usr.bin/ftp/fetch.c
cvs rdiff -u -r1.162 -r1.163 src/usr.bin/ftp/ftp.c
cvs rdiff -u -r1.119 -r1.120 src/usr.bin/ftp/main.c
cvs rdiff -u -r1.155 -r1.156 src/usr.bin/ftp/util.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/ftp/fetch.c
diff -u src/usr.bin/ftp/fetch.c:1.194 src/usr.bin/ftp/fetch.c:1.195
--- src/usr.bin/ftp/fetch.c:1.194 Fri Sep 16 15:39:26 2011
+++ src/usr.bin/ftp/fetch.c Sat Dec 10 05:53:58 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: fetch.c,v 1.194 2011/09/16 15:39:26 joerg Exp $ */
+/* $NetBSD: fetch.c,v 1.195 2011/12/10 05:53:58 lukem Exp $ */
/*-
* Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.194 2011/09/16 15:39:26 joerg Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.195 2011/12/10 05:53:58 lukem Exp $");
#endif /* not lint */
/*
@@ -52,6 +52,7 @@ __RCSID("$NetBSD: fetch.c,v 1.194 2011/0
#include <arpa/ftp.h>
#include <arpa/inet.h>
+#include <assert.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
@@ -1125,6 +1126,7 @@ fetch_url(const char *url, const char *p
(void)xsignal(SIGQUIT, psummary);
oldintr = xsignal(SIGINT, aborthttp);
+ assert(rcvbuf_size > 0);
if ((size_t)rcvbuf_size > bufsize) {
if (xferbuf)
(void)free(xferbuf);
Index: src/usr.bin/ftp/ftp.c
diff -u src/usr.bin/ftp/ftp.c:1.162 src/usr.bin/ftp/ftp.c:1.163
--- src/usr.bin/ftp/ftp.c:1.162 Fri Sep 16 15:39:26 2011
+++ src/usr.bin/ftp/ftp.c Sat Dec 10 05:53:58 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: ftp.c,v 1.162 2011/09/16 15:39:26 joerg Exp $ */
+/* $NetBSD: ftp.c,v 1.163 2011/12/10 05:53:58 lukem Exp $ */
/*-
* Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -92,7 +92,7 @@
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else
-__RCSID("$NetBSD: ftp.c,v 1.162 2011/09/16 15:39:26 joerg Exp $");
+__RCSID("$NetBSD: ftp.c,v 1.163 2011/12/10 05:53:58 lukem Exp $");
#endif
#endif /* not lint */
@@ -108,6 +108,7 @@ __RCSID("$NetBSD: ftp.c,v 1.162 2011/09/
#include <arpa/ftp.h>
#include <arpa/telnet.h>
+#include <assert.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
@@ -765,6 +766,7 @@ sendrequest(const char *cmd, const char
if (dout == NULL)
goto abort;
+ assert(sndbuf_size > 0);
if ((size_t)sndbuf_size > bufsize) {
if (buf)
(void)free(buf);
@@ -1026,6 +1028,7 @@ recvrequest(const char *cmd, const char
progress = 0;
preserve = 0;
}
+ assert(rcvbuf_size > 0);
if ((size_t)rcvbuf_size > bufsize) {
if (buf)
(void)free(buf);
Index: src/usr.bin/ftp/main.c
diff -u src/usr.bin/ftp/main.c:1.119 src/usr.bin/ftp/main.c:1.120
--- src/usr.bin/ftp/main.c:1.119 Fri Sep 16 15:39:26 2011
+++ src/usr.bin/ftp/main.c Sat Dec 10 05:53:58 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.119 2011/09/16 15:39:26 joerg Exp $ */
+/* $NetBSD: main.c,v 1.120 2011/12/10 05:53:58 lukem Exp $ */
/*-
* Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
@@ -98,7 +98,7 @@ __COPYRIGHT("@(#) Copyright (c) 1985, 19
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
-__RCSID("$NetBSD: main.c,v 1.119 2011/09/16 15:39:26 joerg Exp $");
+__RCSID("$NetBSD: main.c,v 1.120 2011/12/10 05:53:58 lukem Exp $");
#endif
#endif /* not lint */
@@ -139,9 +139,8 @@ main(int volatile argc, char **volatile
struct passwd *pw;
char *cp, *ep, *anonpass, *upload_path, *src_addr;
const char *anonuser;
- int dumbterm, s, isupload;
+ int dumbterm, isupload;
size_t len;
- socklen_t slen;
tzset();
setlocale(LC_ALL, "");
@@ -204,35 +203,6 @@ main(int volatile argc, char **volatile
if (cp != NULL && strlcpy(netrc, cp, sizeof(netrc)) >= sizeof(netrc))
errx(1, "$NETRC `%s': %s", cp, strerror(ENAMETOOLONG));
- /*
- * Get the default socket buffer sizes if we don't already have them.
- * It doesn't matter which socket we do this to, because on the first
- * call no socket buffer sizes will have been modified, so we are
- * guaranteed to get the system defaults.
- */
- s = socket(AF_INET, SOCK_STREAM, 0);
- if (s == -1)
- err(1, "Can't create socket to determine default socket sizes");
- slen = sizeof(rcvbuf_size);
- if (getsockopt(s, SOL_SOCKET, SO_RCVBUF,
- (void *)&rcvbuf_size, &slen) == -1)
- err(1, "Unable to get default rcvbuf size");
- slen = sizeof(sndbuf_size);
- if (getsockopt(s, SOL_SOCKET, SO_SNDBUF,
- (void *)&sndbuf_size, &slen) == -1)
- err(1, "Unable to get default sndbuf size");
- (void)close(s);
- /* sanity check returned buffer sizes */
- if (rcvbuf_size <= 0)
- rcvbuf_size = 8 * 1024;
- if (sndbuf_size <= 0)
- sndbuf_size = 8 * 1024;
-
- if (sndbuf_size > 8 * 1024 * 1024)
- sndbuf_size = 8 * 1024 * 1024;
- if (rcvbuf_size > 8 * 1024 * 1024)
- rcvbuf_size = 8 * 1024 * 1024;
-
marg_sl = ftp_sl_init();
if ((tmpdir = getenv("TMPDIR")) == NULL)
tmpdir = _PATH_TMP;
Index: src/usr.bin/ftp/util.c
diff -u src/usr.bin/ftp/util.c:1.155 src/usr.bin/ftp/util.c:1.156
--- src/usr.bin/ftp/util.c:1.155 Sat Jun 5 13:59:39 2010
+++ src/usr.bin/ftp/util.c Sat Dec 10 05:53:58 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: util.c,v 1.155 2010/06/05 13:59:39 lukem Exp $ */
+/* $NetBSD: util.c,v 1.156 2011/12/10 05:53:58 lukem Exp $ */
/*-
* Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: util.c,v 1.155 2010/06/05 13:59:39 lukem Exp $");
+__RCSID("$NetBSD: util.c,v 1.156 2011/12/10 05:53:58 lukem Exp $");
#endif /* not lint */
/*
@@ -1080,6 +1080,32 @@ strsuftoi(const char *arg)
void
setupsockbufsize(int sock)
{
+ socklen_t slen;
+
+ if (0 == rcvbuf_size) {
+ slen = sizeof(rcvbuf_size);
+ if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF,
+ (void *)&rcvbuf_size, &slen) == -1)
+ err(1, "Unable to determine rcvbuf size");
+ if (rcvbuf_size <= 0)
+ rcvbuf_size = 8 * 1024;
+ if (rcvbuf_size > 8 * 1024 * 1024)
+ rcvbuf_size = 8 * 1024 * 1024;
+ DPRINTF("setupsockbufsize: rcvbuf_size determined as %d\n",
+ rcvbuf_size);
+ }
+ if (0 == sndbuf_size) {
+ slen = sizeof(sndbuf_size);
+ if (getsockopt(sock, SOL_SOCKET, SO_SNDBUF,
+ (void *)&sndbuf_size, &slen) == -1)
+ err(1, "Unable to determine sndbuf size");
+ if (sndbuf_size <= 0)
+ sndbuf_size = 8 * 1024;
+ if (sndbuf_size > 8 * 1024 * 1024)
+ sndbuf_size = 8 * 1024 * 1024;
+ DPRINTF("setupsockbufsize: sndbuf_size determined as %d\n",
+ sndbuf_size);
+ }
if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
(void *)&sndbuf_size, sizeof(sndbuf_size)) == -1)