Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Mangement of fdtable[]



On Thu, 15 Oct 2015 17:22:52 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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



Messages sorted by: Reverse Date, Date, Thread, Author