zsh-workers
 help / color / mirror / code / Atom feed
* RE: zftp problem (OS dependent)
       [not found] <001501be2eaa$13c41c50$21c9ca95@mowp.siemens.ru>
@ 1998-12-24 11:10 ` Andrej Borsenkow
  1999-01-09 16:01   ` PATCH: 3.1.5-pws-4: " Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Andrej Borsenkow @ 1998-12-24 11:10 UTC (permalink / raw)
  To: ZSH workers mailing list



> -----Original Message-----
> From:
> Sent: Wednesday, December 23, 1998 10:26 PM
> To: ZSH workers mailing list
> Subject: zftp problem (OS dependent)
>
>
> I just found a very nice problem here ...
>
> Obviously, my system has a bug, that does not allow zftp open to be called
> second time :-) The problem is related to fcntl(x, F_DUPFD, ...)
> If I remove
> zfmoved(), it works nicely. If zmovefd() is used, the first time I can
> connect; but after that, all connects fail with
>
> "address family is not supported by protocol family"
>
> I admit, that it is OS bug, but it is probably won't be fixed soon ... Is
> there any possible workaround?
>
>


Sorry for followup ...

It looks, that we can duplicate connected socket. It means, that zfmovefd()
should be called after connect succeeds. It seems to be safe, as if connect
fails, we close fd anyway.

Merry Christmas to everybody

/andrej


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

* PATCH: 3.1.5-pws-4: zftp problem (OS dependent)
  1998-12-24 11:10 ` zftp problem (OS dependent) Andrej Borsenkow
@ 1999-01-09 16:01   ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 1999-01-09 16:01 UTC (permalink / raw)
  To: ZSH workers mailing list

"Andrej Borsenkow" wrote:
> It looks, that we can duplicate connected socket. It means, that zfmovefd()
> should be called after connect succeeds. It seems to be safe, as if connect
> fails, we close fd anyway.

OK, this patch moves the zfmovefd() later.  It also does it with the
data connection, just to try to keep things simple (though for all I
know that will now break on some OS...).

*** Src/Modules/zftp.c.movefd	Sat Dec 19 14:51:48 1998
--- Src/Modules/zftp.c	Sat Jan  9 16:54:20 1999
***************
*** 832,838 ****
  	zwarnnam(name, "Must set preference S or P to transfer data", NULL, 0);
  	return 1;
      }
!     zdfd = zfmovefd(socket(AF_INET, SOCK_STREAM, 0));
      if (zdfd < 0) {
  	zwarnnam(name, "can't get data socket: %e", NULL, errno);
  	return 1;
--- 832,838 ----
  	zwarnnam(name, "Must set preference S or P to transfer data", NULL, 0);
  	return 1;
      }
!     zdfd = socket(AF_INET, SOCK_STREAM, 0);
      if (zdfd < 0) {
  	zwarnnam(name, "can't get data socket: %e", NULL, errno);
  	return 1;
***************
*** 1029,1034 ****
--- 1029,1041 ----
  	    return 1;
  	}
  	zdfd = newfd;		/* this is now the actual data fd */
+     } else {
+ 	/*
+ 	 * We avoided dup'ing zdfd up to this point, to try to keep
+ 	 * things simple, so we now need to move it out of the way
+ 	 * of the user-visible fd's.
+ 	 */
+ 	zdfd = zfmovefd(zdfd);
      }
  
  
***************
*** 1671,1677 ****
      }
  
      zsock.sin_port = zservp->s_port;
!     zcfd = zfmovefd(socket(zsock.sin_family, SOCK_STREAM, 0));
      if (zcfd < 0) {
  	zwarnnam(name, "socket failed: %e", NULL, errno);
  	zfunsetparam("ZFTP_HOST");
--- 1678,1684 ----
      }
  
      zsock.sin_port = zservp->s_port;
!     zcfd = socket(zsock.sin_family, SOCK_STREAM, 0);
      if (zcfd < 0) {
  	zwarnnam(name, "socket failed: %e", NULL, errno);
  	zfunsetparam("ZFTP_HOST");
***************
*** 1679,1690 ****
  	return 1;
      }
  
- #if defined(F_SETFD) && defined(FD_CLOEXEC)
-     /* If the shell execs a program, we don't want this fd left open. */
-     len = FD_CLOEXEC;
-     fcntl(zcfd, F_SETFD, &len);
- #endif
- 
      /*
       * now connect the socket.  manual pages all say things like `this is all
       * explained oh-so-wonderfully in some other manual page'.  not.
--- 1686,1691 ----
***************
*** 1719,1724 ****
--- 1720,1738 ----
      zfsetparam("ZFTP_IP", ztrdup(inet_ntoa(zsock.sin_addr)), ZFPM_READONLY);
      /* now we can talk to the control connection */
      zcfinish = 0;
+ 
+ 
+     /*
+      * Move the fd out of the user-visible range.  We need to do
+      * this after the connect() on some systems.
+      */
+     zcfd = zfmovefd(zcfd);
+ 
+ #if defined(F_SETFD) && defined(FD_CLOEXEC)
+     /* If the shell execs a program, we don't want this fd left open. */
+     len = FD_CLOEXEC;
+     fcntl(zcfd, F_SETFD, &len);
+ #endif
  
      len = sizeof(zsock);
      if (getsockname(zcfd, (struct sockaddr *)&zsock, &len) < 0) {

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


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

end of thread, other threads:[~1999-01-09 16:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <001501be2eaa$13c41c50$21c9ca95@mowp.siemens.ru>
1998-12-24 11:10 ` zftp problem (OS dependent) Andrej Borsenkow
1999-01-09 16:01   ` PATCH: 3.1.5-pws-4: " Peter Stephenson

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).