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

Closing descriptors in forked (pipe) command



Hello,
in db/gdbm module, I do:
        addmodulefd(gdbm_fdesc(dbf), FDT_MODULE);

this should lead to problem, but it behaves the same as with
FDT_INTERNAL, i.e. following:

% ztie -d db/gdbm -f ~/db3 mybase2
% fun() { while read line; do echo $line; done }
% eval "print -rl -- \${(kv)mybase2[@]}" | fun
% echo $mybase2

The point is: forked process inherits database connection. GDBM cannot
have multiple writers (open is in write mode). Above outputs:

(Dbase accessed)
testkey
testdata

(Dbase accessed)
testkey
testdata

"(Dbase accessed)" is printf from code where $mybase2 turns out to be
empty for given key and database fetch is ordered. So it's visible that
there is fork because database is accessed twice – $mybase2 is still
empty at line "echo $mybase2". Good that GDBM handles change to
file-descriptor's file position pointer (AFAIK it's shared between FDs),
and reads the data again correctly. With write it also works, but
potentially the database might get corrupted silently:

% ztie -d db/gdbm -f ~/db3 mybase2
% fun() { while read line; do echo $line; done }
% eval "mybase2[漢]=字" | fun
(Dbase accessed)
% echo $mybase2[漢]
(Dbase accessed)
字

Maybe it would be good to solve this? FDT_FORKCLOSE or something, there
is closeallelse(), for multiio, didn't go deeper in this.

-- 
  Sebastian Gniazdowski
  psprint2@xxxxxxxxxxxx



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