Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/ftp Move determination of socket buffer sizes from s...
details: https://anonhg.NetBSD.org/src/rev/2f092c1685ba
branches: trunk
changeset: 771943:2f092c1685ba
user: lukem <lukem%NetBSD.org@localhost>
date: Sat Dec 10 05:53:58 2011 +0000
description:
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.
diffstat:
usr.bin/ftp/fetch.c | 6 ++++--
usr.bin/ftp/ftp.c | 7 +++++--
usr.bin/ftp/main.c | 36 +++---------------------------------
usr.bin/ftp/util.c | 30 ++++++++++++++++++++++++++++--
4 files changed, 40 insertions(+), 39 deletions(-)
diffs (192 lines):
diff -r c1579947cc5d -r 2f092c1685ba usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c Sat Dec 10 02:46:07 2011 +0000
+++ b/usr.bin/ftp/fetch.c Sat Dec 10 05:53:58 2011 +0000
@@ -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 @@
#include <arpa/ftp.h>
#include <arpa/inet.h>
+#include <assert.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
@@ -1125,6 +1126,7 @@
(void)xsignal(SIGQUIT, psummary);
oldintr = xsignal(SIGINT, aborthttp);
+ assert(rcvbuf_size > 0);
if ((size_t)rcvbuf_size > bufsize) {
if (xferbuf)
(void)free(xferbuf);
diff -r c1579947cc5d -r 2f092c1685ba usr.bin/ftp/ftp.c
--- a/usr.bin/ftp/ftp.c Sat Dec 10 02:46:07 2011 +0000
+++ b/usr.bin/ftp/ftp.c Sat Dec 10 05:53:58 2011 +0000
@@ -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 @@
#include <arpa/ftp.h>
#include <arpa/telnet.h>
+#include <assert.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
@@ -765,6 +766,7 @@
if (dout == NULL)
goto abort;
+ assert(sndbuf_size > 0);
if ((size_t)sndbuf_size > bufsize) {
if (buf)
(void)free(buf);
@@ -1026,6 +1028,7 @@
progress = 0;
preserve = 0;
}
+ assert(rcvbuf_size > 0);
if ((size_t)rcvbuf_size > bufsize) {
if (buf)
(void)free(buf);
diff -r c1579947cc5d -r 2f092c1685ba usr.bin/ftp/main.c
--- a/usr.bin/ftp/main.c Sat Dec 10 02:46:07 2011 +0000
+++ b/usr.bin/ftp/main.c Sat Dec 10 05:53:58 2011 +0000
@@ -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 @@
#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 @@
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 @@
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;
diff -r c1579947cc5d -r 2f092c1685ba usr.bin/ftp/util.c
--- a/usr.bin/ftp/util.c Sat Dec 10 02:46:07 2011 +0000
+++ b/usr.bin/ftp/util.c Sat Dec 10 05:53:58 2011 +0000
@@ -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 @@
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)
Home |
Main Index |
Thread Index |
Old Index