From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22123 invoked by alias); 11 Aug 2010 16:30:01 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 28145 Received: (qmail 2239 invoked from network); 11 Aug 2010 16:29:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at klanderman.net does not designate permitted sender hosts) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <19554.52743.499270.657398@gargle.gargle.HOWL> Date: Wed, 11 Aug 2010 12:21:27 -0400 From: Greg Klanderman To: Zsh list Subject: ztcp should not pick fd 0 Reply-To: gak@klanderman.net X-Mailer: VM 8.0.12-devo-585 under 21.4 (patch 17) "Jumbo Shrimp" XEmacs Lucid (i386-redhat-linux) I'm using ztcp to connect to a server; when the connection is lost and needs to be re-opened from within the completion system (compctl), calling 'ztcp ' will actually choose fd 0 for the socket file descriptor which is hosing other parts of my program (calling out to a python process specifically). I can work around this problem by requesting the previous fd with the '-d' option (I suppose that's not 100% safe because after closing the original socket that fd might get reallocated in the intervening time), but it would be really nice if ztcp could be made to never choose fds 0 through 2. This is also a problem because if you try to close fd 0 with ztcp you'll get the error '0 is an invalid argument to -c'. The obvious patch below does not work because movefd() marks the fd as FDT_INTERNAL, and that causes the fd to get closed when external programs are exec'd. This calls into question the other use of movefd in tcp.c as well. Suggestions welcome.. Greg Index: Src/Modules/tcp.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/tcp.c,v retrieving revision 1.51 diff -u -r1.51 tcp.c --- Src/Modules/tcp.c 22 Sep 2009 16:04:16 -0000 1.51 +++ Src/Modules/tcp.c 11 Aug 2010 15:34:42 -0000 @@ -668,6 +668,16 @@ return 1; } } + else { + /* if fd is < 10, move it up to be >= 10 */ + int oldfd = sess->fd; + sess->fd = movefd(sess->fd); + if (sess->fd < 0) { + zerrnam(nam, "could not move socket fd %d: %e", oldfd, errno); + return 1; + } + } + setiparam("REPLY", sess->fd);