From owner-freebsd-current@FreeBSD.ORG Sun Oct 24 23:45:45 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 95AE3106564A for ; Sun, 24 Oct 2010 23:45:45 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-iw0-f182.google.com (mail-iw0-f182.google.com [209.85.214.182]) by mx1.freebsd.org (Postfix) with ESMTP id 58C2E8FC18 for ; Sun, 24 Oct 2010 23:45:45 +0000 (UTC) Received: by iwn39 with SMTP id 39so3589782iwn.13 for ; Sun, 24 Oct 2010 16:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=nl74FbOrHRTdnKFf4chFFCVf6KjE+brlFbRY38vRdGs=; b=XHjJ+VdfaEZC/2+XXpa+13cIl30f0JZWBxGrkxaY5XvZSAtftuUQgFRJYe7YVV+RPk kJRJq0Kto/Oi/E80plG5aJO5pf2EdVdK+enhj/RHv+T75s5bUVJ81jeaH69Bf1q7CoPB P7l9g2COoBlP8MUbgxFb3Sj5IugjYLszvL6SQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=oDr1N5atz4AbO+i+oUraaBE+DEJsOgoV1ruBESek0JhUQ7CUCIj+jsIia8sBgX5f7H TK0rA4bf+SYSiD8phBx0E2NsEilkMyZeo5VDrqalviIWssnlSy5xZP9xYkBnvhW0ADjJ 9mu194M/VaIiSt7OQGqLd0kFYriaRvnszYCO4= Received: by 10.231.31.135 with SMTP id y7mr5093455ibc.38.1287962219020; Sun, 24 Oct 2010 16:16:59 -0700 (PDT) Received: from mark-laptop-bsd.mark-home (Mail1.sandvine.com [64.7.137.162]) by mx.google.com with ESMTPS id 34sm7095406ibi.2.2010.10.24.16.16.57 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 24 Oct 2010 16:16:57 -0700 (PDT) Date: Sun, 24 Oct 2010 19:16:44 -0400 From: Mark Johnston To: freebsd-current@freebsd.org Message-ID: <20101024231642.GB2123@mark-laptop-bsd.mark-home> References: <20101024231119.GA2123@mark-laptop-bsd.mark-home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20101024231119.GA2123@mark-laptop-bsd.mark-home> User-Agent: Mutt/1.5.20 (2009-06-14) Subject: [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: Sun, 24 Oct 2010 23:45:45 -0000 Hello, 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. 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. 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. Thanks, -Mark 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(); /* 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; }