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

PATCH: 3.1.5-pws-4: zftp problem (OS dependent)



"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@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



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