-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hi!
Am 22.01.2005 um 18:37 schrieb Stuart Brorson:
* Joshua suggested incorporated including the pid into the lockfile name. My
questions is: Why? Using only the schematic.sch.lock filename makes the lock
independent of which program or which pid created the lock. Then, any program
which wishes to write the file must only look to see if the corresponding .lock
file exists. If I stick the pid in the filename, then I need to look for any
file of the form schematic.sch.*, which is a grep-style operation on the whole
directory from within a C program -- kind of a PITA if you ask me.
You are mainly correct here, but...
If yout program looks for the lock file and if it does not find on just creates it, you are vulnerabel to race conditions.
In early UNIX times, there was creat(2) it was able to return EEXISTS when it was asket to create a file. This was the usual way to create a lock file. I know, creat(2) is obsolete today, the man page tells me to use open(2) instead. However, I cannot remember havon seen open(2) returing EEXISTS. You must be sure to use an atomic operation to check for the existencce of the lock and to aquire it. creat(2) was ok in non networked environments.
I would also suggest to use an atomic method to 'create' the ouztput file upon saving. A combination of link(2) and rename(2) could do this job. First write the new file into a temorary file, then create a backup copy using link(2) and as the last step use rename to replace the original file.
That's not to rubbish the idea. Rather, I am wonder what the advantage is of
having the pid in the filename. I do realize that other unix programs do this,
but I don't know why they do, or what the advantage is.
The reason to put a pid into a file name is to ensure, that no two processes on the same machine use the same file. So several instances of a program can create temporary files without interfeering wich each other. This is the exact opposite of what you want to achieve by using a lock file.
OTOH, including the pid into the name of the temp file used during saving would be a good idea.
73, Mario
- -- Mario Klebsch [EMAIL PROTECTED]
PGP-Key available at http://www.klebsch.de/public.key
Fingerprint DSS: EE7C DBCC D9C8 5DC1 D4DB 1483 30CE 9FB2 A047 9CE0
Diffie-Hellman: D447 4ED6 8A10 2C65 C5E5 8B98 9464 53FF 9382 F518
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
iD8DBQFB8rdpMM6fsqBHnOARAoYpAKCjLYjC8P9Le24KvdudivtO6r7+8ACfVuWy Y4eH1ZsMBaLhKuwZLBJs8OA= =ZDt6 -----END PGP SIGNATURE-----
