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

Re: Closing descriptors in forked (pipe) command



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.

} 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.

You/we certainly may wish to document that it is dangerous to assume
that parent and subshell can both manipulate the tied parameter, but
it would be incorrect to automatically close the file descriptor in
either of them.

This is actually part of the reason why bin_ztie() uses GDBM_SYNC
when opening the database file.



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