From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1437 invoked from network); 9 Jan 1999 16:18:43 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 9 Jan 1999 16:18:43 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id LAA06718; Sat, 9 Jan 1999 11:17:40 -0500 (EST) Resent-Date: Sat, 9 Jan 1999 11:17:40 -0500 (EST) Message-Id: <9901091601.AA27679@ibmth.df.unipi.it> To: "ZSH workers mailing list" Subject: PATCH: 3.1.5-pws-4: zftp problem (OS dependent) In-Reply-To: ""Andrej Borsenkow""'s message of "Thu, 24 Dec 1998 14:10:17 NFT." <001f01be2f2d$fd08aab0$21c9ca95@mowp.siemens.ru> Date: Sat, 09 Jan 1999 17:01:29 +0100 From: Peter Stephenson Resent-Message-ID: <"4Vth_3.0.se1.a4ubs"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4888 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu "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 Tel: +39 050 844536 WWW: http://www.ifh.de/~pws/ Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy