From owner-freebsd-current@FreeBSD.ORG Fri Nov 5 08:50:39 2010 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CD3771065670 for ; Fri, 5 Nov 2010 08:50:39 +0000 (UTC) (envelope-from nick@van-laarhoven.org) Received: from cpsmtpb-ews02.kpnxchange.com (cpsmtpb-ews02.kpnxchange.com [213.75.39.5]) by mx1.freebsd.org (Postfix) with ESMTP id 533C08FC17 for ; Fri, 5 Nov 2010 08:50:35 +0000 (UTC) Received: from cpbrm-ews33.kpnxchange.com ([10.94.84.164]) by cpsmtpb-ews02.kpnxchange.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 5 Nov 2010 09:38:31 +0100 Received: from CPSMTPM-EML105.kpnxchange.com ([195.121.3.9]) by cpbrm-ews33.kpnxchange.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 5 Nov 2010 09:38:31 +0100 Received: from uitsmijter.van-laarhoven.org ([81.207.207.222]) by CPSMTPM-EML105.kpnxchange.com with Microsoft SMTPSVC(7.0.6002.18222); Fri, 5 Nov 2010 09:38:30 +0100 Received: from hillary.van-laarhoven.org (Hillary.van-laarhoven.org [10.66.0.100]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by uitsmijter.van-laarhoven.org (Postfix) with ESMTPSA id 01BBB4080; Fri, 5 Nov 2010 09:38:24 +0100 (CET) Mime-Version: 1.0 (Apple Message framework v1081) Content-Type: text/plain; charset=us-ascii From: Nick Hibma In-Reply-To: <20101024231642.GB2123@mark-laptop-bsd.mark-home> Date: Fri, 5 Nov 2010 09:38:24 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20101024231119.GA2123@mark-laptop-bsd.mark-home> <20101024231642.GB2123@mark-laptop-bsd.mark-home> To: Mark Johnston X-Mailer: Apple Mail (2.1081) X-Spam-Status: No, score=-15.4 required=5.0 tests=J_CHICKENPOX_52, UNPARSEABLE_RELAY,USER_IN_WHITELIST,USER_IN_WHITELIST_TO autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on uitsmijter.van-laarhoven.org X-OriginalArrivalTime: 05 Nov 2010 08:38:31.0097 (UTC) FILETIME=[D351AA90:01CB7CC4] X-RcptDomain: freebsd.org Cc: freebsd-current@freebsd.org Subject: Re: [Patch] libfetch - closing the cached FTP connection X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Nov 2010 08:50:40 -0000 Mark, My 2 cents: Isn't it more appropriate to set FD_CLOEXEC on the fd? fcntl(fd, F_SETFD, FD_CLOEXEC);=20 It doesn't sound like you ever want to have a cached connection be = copied into the child. Mum and child calling daddy using the same phone = line isn't going to make the conversation any easier for daddy. Cheers, Nick On 25 Oct 2010, at 01:16, Mark Johnston wrote: > Hello, >=20 > We've run into problems with pkg_add because of some caching behaviour > in libfetch. Specifically, after an FTP transfer, a connection to the > FTP server is held open by the cached_connection pointer in ftp.c. = Thus, > if one requests a file with fetchGetFTP() and later closes the > connection with fclose(), a socket is still held open, and the > descriptor is copied to any child processes. >=20 > What was apparently happening was that we were using pkg_add to = install > a package whose install script started a daemon, which consequently = kept > open a connection to our FTP server. This is "fixed" in our tree with = a > closefrom(2) in pkg_install at an appropriate point, but I thought = that > libfetch should provide some way of forcing a close on the cached > connection so that the above hack isn't necessary. >=20 > My solution is provided in a patch below. It's not particularly = elegant, > but I can't see a better way to go about it. I was hoping to get some > feedback and to see if anyone can come up with a better approach. I'll > also update the libfetch man page if the patch below is acceptable. >=20 > Thanks, > -Mark >=20 > diff --git a/lib/libfetch/fetch.h b/lib/libfetch/fetch.h > index 11a3f77..d379e63 100644 > --- a/lib/libfetch/fetch.h > +++ b/lib/libfetch/fetch.h > @@ -109,6 +109,7 @@ FILE *fetchGetFTP(struct url *, const = char *); > FILE *fetchPutFTP(struct url *, const char *); > int fetchStatFTP(struct url *, struct url_stat *, const = char *); > struct url_ent *fetchListFTP(struct url *, const char *); > +void fetchCloseCachedFTP(); >=20 > /* Generic functions */ > FILE *fetchXGetURL(const char *, struct url_stat *, const = char *); > diff --git a/lib/libfetch/ftp.c b/lib/libfetch/ftp.c > index 0983a76..746ad54 100644 > --- a/lib/libfetch/ftp.c > +++ b/lib/libfetch/ftp.c > @@ -1204,3 +1204,12 @@ fetchListFTP(struct url *url __unused, const = char *flags __unused) > warnx("fetchListFTP(): not implemented"); > return (NULL); > } > + > +/* > + * Force close the cached connection. > + */ > +void > +fetchCloseCachedFTP() > +{ > + ftp_disconnect(cached_connection); > +} > diff --git a/usr.sbin/pkg_install/lib/url.c = b/usr.sbin/pkg_install/lib/url.c > index 914ce39..68f31bb 100644 > --- a/usr.sbin/pkg_install/lib/url.c > +++ b/usr.sbin/pkg_install/lib/url.c > @@ -163,5 +163,6 @@ fileGetURL(const char *base, const char *spec, int = keep_package) > printf("tar command returns %d status\n", WEXITSTATUS(pstat)); > if (rp && (isatty(0) || Verbose)) > printf(" Done.\n"); > + fetchCloseCachedFTP(); > return rp; > } > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to = "freebsd-current-unsubscribe@freebsd.org"