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

Re: Closing descriptors in forked (pipe) command

On Sat, Feb 18, 2017, at 09:02 PM, Bart Schaefer wrote:
> On Feb 18,  4:45am, Sebastian Gniazdowski wrote:
> }
> } in db/gdbm module, I do:
> }         addmodulefd(gdbm_fdesc(dbf), FDT_MODULE);
> } 
> } The point is: forked process inherits database connection. GDBM cannot
> } have multiple writers (open is in write mode).
> That's not true -- "man gdbm" even mentions:
>    If  the  database  was  opened with the GDBM_NOLOCK flag, the user may
>    wish to perform their own file locking on the database file  in  order
>    to prevent multiple writers operating on the same file simultaneously.

This would make GDBM quite standout, except I probably superficially
interpreted what I was reading. My opinion about GDBM comes from the
fact that I cannot have reader + writer with gdbmtool, i.e. run once
"gdbmtool -r db", then "gdbmtool db" – first program will stop working:

stdin:1.5: cannot open db: Can't be reader

The superficial reading was one other DBM database that was stating
boldly about no simultaneous access, but I think it was also stating
that multiple threads are possible. Sorry cannot find that again. But
this would reveal that it can be about proper locking, not simultaneous
access itself. Either way GDBM has nice potential but I might not be
able to leverage it in the module. Fast ztie, hash scan, untie is quite
much as custom locking & unlocking to access database.

> } Maybe it would be good to solve this? FDT_FORKCLOSE or something, there
> } is closeallelse(), for multiio, didn't go deeper in this.
> In the general case a subshell should be inheriting all descriptors from
> the parent, and it's up to the shell programmer not to do stupid things.
> Consider the case where the parent shell wishes to ztie to the database,
> fork off a subshell that will make use of the tied parameter, and then
> go on to exec something else or otherwise exit, leaving the subshell to
> manage the database.

Ok, with file position pointer sanity, and "file has changed" sanity of
GDBM, this is in quite good state and the use case you wrote is
available to the user.

Sebastian Gniazdowski

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