From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10988 invoked from network); 26 Oct 2001 13:14:07 -0000 Received: from ns2.primenet.com.au (HELO primenet.com.au) (?gvTWpKC3eRER2UGNLB3yNUJta3Xlk7Au?@203.24.36.3) by ns1.primenet.com.au with SMTP; 26 Oct 2001 13:14:07 -0000 Received: (qmail 5236 invoked from network); 26 Oct 2001 13:14:04 -0000 Received: from sunsite.dk (130.225.247.90) by proxy.melb.primenet.com.au with SMTP; 26 Oct 2001 13:14:04 -0000 Received: (qmail 29055 invoked by alias); 26 Oct 2001 13:13:53 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16176 Received: (qmail 29042 invoked from network); 26 Oct 2001 13:13:50 -0000 To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: tcp/zftp close In-reply-to: "Peter Stephenson"'s message of "Fri, 26 Oct 2001 13:02:06 BST." <11058.1004097726@csr.com> Date: Fri, 26 Oct 2001 14:13:20 +0100 Message-ID: <11357.1004102000@csr.com> From: Peter Stephenson Peter Stephenson wrote: > Now there's just the matter of > zfclose:3: connection close failed: bad file number > to deal with. This fixes that, but unfortunately invalidates Bart's previous assumption that a TCP session would always have a valid fd number. Given the comment in the second hunk, I don't see an alternative, does anyone? The test (fileno(zfsess->cin) == zfsess->control->fd) is the most dire and unjustifiable paranoia. Index: Src/Modules/tcp.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/tcp.c,v retrieving revision 1.20 diff -u -r1.20 tcp.c --- Src/Modules/tcp.c 2001/10/26 12:06:39 1.20 +++ Src/Modules/tcp.c 2001/10/26 13:07:00 @@ -291,19 +291,21 @@ { int err; - if (sess && sess->fd != -1) + if (sess) { - err = close(sess->fd); - if (err) + if (sess->fd != -1) { - zwarn("connection close failed: %e", NULL, errno); - return -1; + err = close(sess->fd); + if (err) + { + zwarn("connection close failed: %e", NULL, errno); + return -1; + } } zts_delete(sess); return 0; } - zts_delete(sess); return -1; } Index: Src/Modules/zftp.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/zftp.c,v retrieving revision 1.23 diff -u -r1.23 zftp.c --- Src/Modules/zftp.c 2001/10/26 12:06:39 1.23 +++ Src/Modules/zftp.c 2001/10/26 13:07:01 @@ -2679,6 +2679,13 @@ } if (zfsess->cin) { fclose(zfsess->cin); + /* + * We fdopen'd the TCP control fd; since we can't fdclose it, + * we need to perform a full fclose, which invalidates the + * TCP fd. + */ + if (fileno(zfsess->cin) == zfsess->control->fd) + zfsess->control->fd = -1; zfsess->cin = NULL; } if (zfsess->control) { -- Peter Stephenson Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070 ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. **********************************************************************