[Ecls-list] open :supersede and rename-file advise
Geo Carncross
geocar at gmail.com
Thu Nov 29 17:05:33 UTC 2007
On Nov 29, 2007 2:25 AM, Richard M Kreuter <kreuter at progn.net> wrote:
> In my previous message, I forgot to mention an important issue in
> implementing "lazy superseding" on Unix, and perhaps elsewhere. On
> Unix, open files can be shared among multiple processes.
This is true, but without the FFI, ECL has no way of doing this, so
this is assuming we implement an POSIX:FORK routine. FWIW, Windows
can't fork, so this might be a long ways off before we have to deal
with it, but I think you're right that it's important the semantics be
nailed down.
> (2) The implementation could try to do the superseding only when the
> last process closes the file. AFAICT, doing this in general
> requires subsuming the functionality of lsof, which is probably far
> more work than is practical.
Actually, all processes could
flock((tmp=dup(fd)),LOCK_SH),close(fd),fd=tmp; at POSIX:FORK time.
To test to see if you're the last process, simply check to see if you
can upgrade the lock. If flock(fd,LOCK_EX|LOCK_NB); succeeds, then
you're the last lock holder. If it fails, it's someone else's job.
> It gets weirder in more obscure cases of file sharing, e.g., passing
> descriptors over Unix domain sockets. I haven't any intuitions right
> now about these cases.
I think when a fd gets passed using SCM_RIGHTS the locks are
preserved, so the flock() trick should work. I'd have to check, but I
think SCM_RIGHTS is usually used for privilege separation, so it's not
likely the other process could complete the protocol anyway.
More information about the ecl-devel
mailing list