From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22042 invoked by alias); 11 Aug 2010 16:45:02 -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: 28147 Received: (qmail 6723 invoked from network); 11 Aug 2010 16:45:00 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Wed, 11 Aug 2010 17:44:54 +0100 From: Peter Stephenson To: Zsh list Subject: Re: ztcp should not pick fd 0 Message-ID: <20100811174454.5923a2fc@csr.com> In-Reply-To: <19554.52743.499270.657398@gargle.gargle.HOWL> References: <19554.52743.499270.657398@gargle.gargle.HOWL> Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.6 (GTK+ 2.18.9; i686-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 11 Aug 2010 16:44:54.0562 (UTC) FILETIME=[867E8820:01CB3974] X-Scanned-By: MailControl A_09_40_00 (www.mailcontrol.com) on 10.68.0.162 On Wed, 11 Aug 2010 12:21:27 -0400 Greg Klanderman wrote: > 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'. Moving it above 9 is probably OK. I'm trying to work out whether there's any use at present where that might cause problems, but it would have to be somewhere that assumed it was less than 10, which would be an unsafe assumption. It's more consistent to have it over 9, other "magic" file descriptors work like that. > 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. There's nothing very special about fdtable; adding "fdtable[sess->fd] = FDT_EXTERNAL" to the patch on success should be OK, or invent another FDT_ type (fdtable is already exported to modules). The other use in the file may need this too --- it's quite likely the CLOEXEC behaviour of zsh/net/tcp hasn't been thought through, but the default should obviously be the system default of not closing fd's. -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom