>Number: 151866 >Category: bin >Synopsis: [libfetch] [patch] closing the cached FTP connection >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Nov 01 15:10:07 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Mark Johnston >Release: 8.1-RELEASE >Organization: Sandvine Inc. >Environment: FreeBSD mark-laptop-bsd.mark-home 8.1-RELEASE FreeBSD 8.1-RELEASE #2: Mon Oct 25 15:07:21 EDT 2010 r...@mark-laptop-bsd.mark-home:/usr/obj/usr/src/sys/GENERIC i386 >Description: This patch adds a function to libfetch which allows programs to close the cached socket that libfetch holds on to when performing a file transfer.
See http://lists.freebsd.org/pipermail/freebsd-current/2010-October/020694.html >How-To-Repeat: Running this test program and using sockstat demonstrates the issue. #include <stdlib.h> #include <stdio.h> #include <sys/param.h> #include <fetch.h> #define URL "ftp://ftp.freebsd.org/pub/FreeBSD/releases/README.TXT" int main(int argc, char **argv) { char c; FILE *f = fetchGetURL(URL, NULL); if (!f) { printf("Error: could not open connection.\n"); return (1); } while (!feof(f)) { fread(&c, sizeof(char), 1, f); putchar(c); } printf("Transfer complete.\n"); fclose(f); if (fork()) //Close the cached FTP connection. //fetchCloseCachedFTP(); else for ( ;; ) ; return (0); } >Fix: My patch adds a function to libfetch which makes it possible to force close the cached connection. Included is a patch to pkg_add(1) which fixes the problem described in the email. Patch attached with submission follows: 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; } >Release-Note: >Audit-Trail: >Unformatted: _______________________________________________ freebsd-bugs@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-bugs To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"