From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21974 invoked from network); 15 Apr 2005 10:27:34 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 15 Apr 2005 10:27:34 -0000 Received: (qmail 13476 invoked from network); 15 Apr 2005 10:27:28 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 15 Apr 2005 10:27:28 -0000 Received: (qmail 14512 invoked by alias); 15 Apr 2005 10:27:26 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21143 Received: (qmail 14502 invoked from network); 15 Apr 2005 10:27:25 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 15 Apr 2005 10:27:25 -0000 Received: (qmail 13182 invoked from network); 15 Apr 2005 10:27:25 -0000 Received: from mailhost1.csr.com (HELO MAILSWEEPER01.csr.com) (81.105.217.43) by a.mx.sunsite.dk with SMTP; 15 Apr 2005 10:27:14 -0000 Received: from exchange03.csr.com (unverified [10.100.137.60]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Fri, 15 Apr 2005 11:25:33 +0100 Received: from news01.csr.com ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Fri, 15 Apr 2005 11:30:16 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.1/8.12.11) with ESMTP id j3FARBxM004525 for ; Fri, 15 Apr 2005 11:27:11 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.1/8.13.1/Submit) with ESMTP id j3FARBdH004522 for ; Fri, 15 Apr 2005 11:27:11 +0100 Message-Id: <200504151027.j3FARBdH004522@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: Zsh hackers list Subject: Re: PATCH: allocating a new file descriptor In-reply-to: <20050414181020.GA5064@sc> References: <200504121257.j3CCvkXr003286@news01.csr.com> <1050414045748.ZM13551@candle.brasslantern.com> <200504140949.j3E9n5Kp006216@news01.csr.com> <1050414142337.ZM14042@candle.brasslantern.com> <200504141616.j3EGGR7O023489@news01.csr.com> <20050414181020.GA5064@sc> Date: Fri, 15 Apr 2005 11:27:10 +0100 From: Peter Stephenson X-OriginalArrivalTime: 15 Apr 2005 10:30:16.0697 (UTC) FILETIME=[1D9A8690:01C541A6] X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 Stephane Chazelas wrote: > I would find it more consistent to > have: > > sysopen -w file > fd=$REPLY Yes, that could be added to the zsh/system module easily enough, but it would be zsh-specific. I've simply never needed it up to now. > I find the: > > print ... {fd}> file > > that keeps the file open a bit confusing and unconsistent (and > useless). You mean with print? That's why the manual now suggests using it with exec. The syntax is designed to be consistent with existing standard shell syntax, which imposes quite strong limitations. One annoyance is that if you use an older version of the shell, the exec tries to execute {fd} and disappears, which isn't a particularly graceful way of failing. > It would be good to have a sysclose as well. At least until > recently, exec 12>&- didn't work. I had the problem with my > mouse support, where I couldn't close the fd opened by zsocket > for gpm interaction. That syntax is deliberately restricted to single digits and will remain so. You can now do: fd=12 exec {fd}>&- (Presumably you already have the fd in a parameter, in fact.) The socket module is more limited than the tcp module; it doesn't record sessions, so has no way of knowing which fd's you might want to close. That may be why there's no zsocket -c. > I also noticed several problems when fidling with fds used > internally by zsh (zsocket -d10 or -d11 ended up in a core > dump). Yes, it doesn't check for existing use of the fd by the shell. The same problem exists with the new syntax when closing fd's; I've made it check for special fd's, which are those from 10 upwards marked as for internal use. This covers 10, but not 11; I'm not sure what opened that, but I think it's some library rather than the shell itself. If we can track it down it could be marked as in internal use, too. (Maybe it's about time we introduced zwarn and friends to stdarg.h...) Index: Src/exec.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/exec.c,v retrieving revision 1.88 diff -u -r1.88 exec.c --- Src/exec.c 14 Apr 2005 16:24:52 -0000 1.88 +++ Src/exec.c 15 Apr 2005 10:18:15 -0000 @@ -77,7 +77,7 @@ * by zclose. */ /**/ -unsigned char *fdtable; +mod_export unsigned char *fdtable; /* The allocated size of fdtable */ @@ -87,7 +87,7 @@ /* The highest fd that marked with nonzero in fdtable */ /**/ -int max_zsh_fd; +mod_export int max_zsh_fd; /* input fd from the coprocess */ @@ -2360,13 +2360,22 @@ bad = 2; } else { fn->fd1 = (int)getintvalue(v); - bad = errflag; + if (errflag) + bad = 1; + else if (fn->fd1 > max_zsh_fd) + bad = 3; + else if (fn->fd1 >= 10 && + fdtable[fn->fd1] == FDT_INTERNAL) + bad = 4; } if (bad) { - zwarn(bad == 2 ? - "can't close file descriptor from readonly parameter" : - "parameter %s does not contain a file descriptor", - fn->varid, 0); + const char *bad_msg[] = { + "parameter %s does not contain a file descriptor", + "can't close file descriptor from readonly parameter %s", + "file descriptor %d out of range, not closed", + "file descriptor %d used by shell, not closed" + }; + zwarn(bad_msg[bad-1], fn->varid, fn->fd1); execerr(); } } Index: Src/Modules/socket.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/socket.c,v retrieving revision 1.7 diff -u -r1.7 socket.c --- Src/Modules/socket.c 16 Nov 2004 11:05:04 -0000 1.7 +++ Src/Modules/socket.c 15 Apr 2005 10:18:15 -0000 @@ -78,6 +78,11 @@ OPT_ARG(ops, 'd'), 0); return 1; } + if (targetfd <= max_zsh_fd && fdtable[targetfd] != FDT_UNUSED) { + zwarnnam(nam, "file descriptor %d is in use by the shell", + NULL, targetfd); + return 1; + } } if (OPT_ISSET(ops,'l')) { -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. **********************************************************************