From: Justin Mason (jm at domain jmason.org)
Date: Wed 23 Feb 2000 - 17:44:39 GMT
Kathryn Cassidy said:
> Does flock work ok on windows as well as unix as the script has to run on
> both? I've heared rumours that it's a bit flaky on some systems.
I don't know, but I bet it doesn't ;)
Another possibility is to use O_EXCL with the POSIX open system call, you
can do this in Perl using "use POSIX;". A thread on Bugtraq discussed it
earlier this month IIRC.
A simple (ish) mechanism in conjunction with this is to use a file called
"userdata.lock" (assuming your user data file is called "userdata").
Create it using O_EXCL using the POSIX api -- this will ensure that your
proc has exclusive open rights on it -- retry if the open fails, and sleep
between retries.
Once you get the file open, you can then write to the real userdata, then
delete the "userdata.lock" file. Since open(O_EXCL) and unlink() are both
atomic operations you're safe.
BTW to avoid causing deadlock if your proc gets killed, trap signals
appropriately, and also copy your pid into the .lock file; if you limit
the number of open-retries, and your CGI hits the limit, it can then read
the file and kill ($pid, 0) to test if it is still running. If it's not
still running then unlink the lock file and re-enter the retry loop.
Here's hoping the windows support for file locking works OK! ;)
--j.
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:05:29 GMT