zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: tcp/zftp function name
@ 2001-10-26 12:02 Peter Stephenson
  2001-10-26 12:05 ` Peter Stephenson
  2001-10-26 13:13 ` PATCH: tcp/zftp close Peter Stephenson
  0 siblings, 2 replies; 4+ messages in thread
From: Peter Stephenson @ 2001-10-26 12:02 UTC (permalink / raw)
  To: Zsh hackers list

This fixes one of the two remaining problems I'm having with tcp and zftp,
namely an error message from zsh's free().  It seems an undocumented
library function which called free() was insinuating its way in, though
where from I still haven't a clue; gdb couldn't trace it, so it's unlikely
to be a stray bit of zsh.

Now there's just the matter of
  zfclose:3: connection close failed: bad file number
to deal with.

Index: Src/Modules/tcp.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/tcp.c,v
retrieving revision 1.19
diff -u -r1.19 tcp.c
--- Src/Modules/tcp.c	2001/10/14 17:23:30	1.19
+++ Src/Modules/tcp.c	2001/10/26 11:56:38
@@ -194,7 +194,7 @@
 
 /**/
 mod_export void
-freehostent(struct hostent *ptr)
+zfreehostent(struct hostent *ptr)
 {
 }
 
Index: Src/Modules/zftp.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/zftp.c,v
retrieving revision 1.22
diff -u -r1.22 zftp.c
--- Src/Modules/zftp.c	2001/10/26 11:09:48	1.22
+++ Src/Modules/zftp.c	2001/10/26 11:56:38
@@ -1793,7 +1793,7 @@
 		tcp_close(zfsess->control);
 		zfsess->control = NULL;
 	    }
-	    freehostent(zhostp);
+	    zfreehostent(zhostp);
 	    zfunsetparam("ZFTP_HOST");
 	    FAILED();
 	    zwarnnam(name, "socket failed: %e", NULL, errno);
@@ -1821,7 +1821,7 @@
 	}
 
 	if (err) {
-	    freehostent(zhostp);
+	    zfreehostent(zhostp);
 	    zfclose(0);
 	    FAILED();
 	    zwarnnam(name, "connect failed: %e", NULL, errno);
@@ -1842,7 +1842,7 @@
 	zsh_inet_ntop(af, *addrp, pbuf, sizeof(pbuf));
 	zfsetparam("ZFTP_IP", ztrdup(pbuf), ZFPM_READONLY);
     }
-    freehostent(zhostp);
+    zfreehostent(zhostp);
     /* now we can talk to the control connection */
     zcfinish = 0;
 
-- 
Peter Stephenson <pws@csr.com>                  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.
**********************************************************************


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: tcp/zftp function name
  2001-10-26 12:02 PATCH: tcp/zftp function name Peter Stephenson
@ 2001-10-26 12:05 ` Peter Stephenson
  2001-10-26 13:13 ` PATCH: tcp/zftp close Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2001-10-26 12:05 UTC (permalink / raw)
  To: Zsh hackers list

Peter Stephenson wrote:
> It seems an undocumented
> library function which called free() was insinuating its way in, though
> where from I still haven't a clue; gdb couldn't trace it, so it's unlikely
> to be a stray bit of zsh.

Just found it: freehostent() is defined in libnsl, so indeed the patch is
necessary as it stands.

-- 
Peter Stephenson <pws@csr.com>                  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.
**********************************************************************


^ permalink raw reply	[flat|nested] 4+ messages in thread

* PATCH: tcp/zftp close
  2001-10-26 12:02 PATCH: tcp/zftp function name Peter Stephenson
  2001-10-26 12:05 ` Peter Stephenson
@ 2001-10-26 13:13 ` Peter Stephenson
  2001-10-26 17:05   ` Bart Schaefer
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2001-10-26 13:13 UTC (permalink / raw)
  To: Zsh hackers list

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@csr.com>                  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.
**********************************************************************


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: tcp/zftp close
  2001-10-26 13:13 ` PATCH: tcp/zftp close Peter Stephenson
@ 2001-10-26 17:05   ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2001-10-26 17:05 UTC (permalink / raw)
  To: Zsh hackers list

On Oct 26,  2:13pm, Peter Stephenson wrote:
}
} 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?

You could rewrite zftp so as not to require fdopen().

However, I don't think that's necessary.  As long as a not-closed zftp
session always has a tcp session with a valid fd, I think things are safe.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-10-26 17:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-26 12:02 PATCH: tcp/zftp function name Peter Stephenson
2001-10-26 12:05 ` Peter Stephenson
2001-10-26 13:13 ` PATCH: tcp/zftp close Peter Stephenson
2001-10-26 17:05   ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).