Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: tcp/zftp close



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 <pws@xxxxxxx>                  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.
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author