The lockfile wants an fd, which, AFAIK, only exists AFTER you open the
file.

Ah, thanks for that clarification.

You're right: I went back over the details of how file descriptors are
created by the OS, and they're *temporary* non-negative integers based
on what's available, given other file handles currently open, and the
system's OPEN_MAX value -- so there's no way to correlate a pathname
or a pathname namestring to a particular file handler.

So you have to open the file in Lisp too, via, with-open-file or
open or whatever.  This will produce a fd-stream object and then you can
use sys:fd-stream-fd to get the fd associated with that file.

I found it simpler to write a wrapper function in C around the fcntl()
call: the wrapper takes the file name string, tries to create the fd
then and there, and if it's successful, sets/removes the lock.

Logically, it's probably no different to use (with-open-file), get the
fd from (sys:fd-stream-fd) and call fcntl() with that fd as you
suggested, but this interface seems simpler and cleaner to me.

Thanks again for your help with this.

Reply via email to