# include "../hdr/macros.h"
Try repeatedly (`count' times) to create `lockfile' mode 444.
Sleep 10 seconds between tries.
If `lockfile' is successfully created, write the process ID
`pid' in `lockfile' (in binary), and return 0.
If `lockfile' exists and it hasn't been modified within the last
minute, and either the file is empty or the process ID contained
in the file is not the process ID of any existing process,
`lockfile' is removed and it tries again to make `lockfile'.
After `count' tries, or if the reason for the create failing
is something other than EACCES, return xmsg().
Unlockit will return 0 if the named lock exists, contains
the given pid, and is successfully removed; -1 otherwise.
lockit(lockfile
,count
,pid
)
for (++count
; --count
; sleep(10)) {
if ((fd
=creat(lockfile
,0444)) >= 0) {
write(fd
,&pid
,sizeof(pid
));
return(xmsg(lockfile
,"lockit"));
ltime
-= Statbuf
.st_mtime
;
if ((fd
= open(lockfile
,0)) < 0)
if (read(fd
,&opid
,sizeof(opid
)) != sizeof(opid
)) {
if (kill(opid
,0) == -1 && errno
== ESRCH
) {
if ((fd
= open(lockfile
,0)) < 0)
n
= read(fd
,&opid
,sizeof(opid
));
if (n
== sizeof(opid
) && opid
== pid
)
return(unlink(lockfile
));