From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7707 invoked by alias); 16 Oct 2015 19:50:57 -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: 36879 Received: (qmail 3897 invoked from network); 16 Oct 2015 19:50:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Originating-IP: [80.3.228.158] X-Spam: 0 X-Authority: v=2.1 cv=AJvf2gUA c=1 sm=1 tr=0 a=P+FLVI8RzFchTbbqTxIDRw==:117 a=P+FLVI8RzFchTbbqTxIDRw==:17 a=NLZqzBF-AAAA:8 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=3Bu0VVdcLDdEb-x9qD0A:9 a=CjuIK1q_8ugA:10 Date: Fri, 16 Oct 2015 20:44:57 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Mangement of fdtable[] Message-ID: <20151016204457.75371664@ntlworld.com> In-Reply-To: <151015172252.ZM30709@torch.brasslantern.com> References: <151015172252.ZM30709@torch.brasslantern.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 15 Oct 2015 17:22:52 -0700 Bart Schaefer wrote: > I was puzzling over Yen Chi Hsuan's bug report in 36866 so was looking > through tcp.c and noticed that it opens file descriptors with socket() > without marking them used in fdtable[]. The only time they're handled > "properly" is with "ztcp -l" which makes a movefd() call. > > I think this means some fds may be closed in some cases they shouldn't, > or conversely left open in cases they shouldn't. This may apply to fds > in other modules, e.g., the descriptor from gdbm_open() in db_gdbm.c. Highly likely; this is probably just wrong. > This further led me to notice that when descriptors are manipulated in > utils.c, it carefully calls the static check_fd_table() function every > time to be sure the descriptor has a slot in the table before an FDT_* > value is poked for it. Other parts of the code (mostly exec.c) simply > reference fdtable[N] without error checking. > > I guess this is OK because fdtable[] is allocated zopenmax() slots in > zsh_main(), but it seems inconsistent if not actually wrong. A lot of the fd code in exec.c is actually involved with opening the fd as a redirection in the first place, so it might actually be correct. pws