* ulockf - this routine will create a lock file (file).
* If one already exists, the create time is checked for
* older than the age time (atime).
* If it is older, an attempt will be made to unlink it
static char tempfile
[NAMESIZE
];
sprintf(tempfile
, "LTMP.%d", pid
);
if (onelock(pid
, tempfile
, file
) == -1) {
/* get status to check age of the lock file */
ret
= stat(file
, &stbuf
);
ASSERT(ret
!= -1, "LOCK PROBLEM - %s", file
);
if ((ptime
- stbuf
.st_ctime
) < atime
) {
/* file not old enough to delete */
ASSERT(ret
!= -1, "LOCK PROBLEM - %s", file
);
ret
= onelock(pid
, tempfile
, file
);
ASSERT(ret
== 0, "LOCK PROBLEM - %s", file
);
#define MAXLOCKS 10 /* maximum number of lock files */
char *Lockfile
[MAXLOCKS
];
* stlock(name) put name in list of lock files
for (i
= 0; i
< Nlocks
; i
++) {
ASSERT(i
< MAXLOCKS
, "TOO MANY LOCKS %d", i
);
p
= calloc(strlen(name
) + 1, sizeof (char));
ASSERT(p
!= NULL
, "CAN NOT ALLOCATE FOR %s", name
);
* rmlock(name) remove all lock files in list
for (i
= 0; i
< Nlocks
; i
++) {
|| strcmp(name
, Lockfile
[i
]) == SAME
) {
/* this stuff from pjw */
/* /usr/pjw/bin/recover - check pids to remove unnecessary locks */
/* isalock(name) returns 0 if the name is a lock */
/* unlock(name) unlocks name if it is a lock*/
/* onelock(pid,tempfile,name) makes lock a name
on behalf of pid. Tempfile must be in the same
/* lock(pid,tempfile,names) either locks all the
isalock(name
) char *name
;
if(stat(name
,&xstat
)<0) return(0);
if(xstat
.st_size
!=sizeof(int)) return(0);
if(isalock(name
)) return(unlink(name
));
onelock(pid
,tempfile
,name
) char *tempfile
,*name
;
write(fd
,&pid
,sizeof(int));
if(link(tempfile
,name
)<0)
lock(pid
,tempfile
,names
) char *tempfile
,**names
;
{ if(onelock(pid
,tempfile
,names
[i
])==0) continue;
for(j
=0;j
<i
;j
++) unlink(names
[j
]);
* delock(s) remove a lock file
sprintf(ln
, "%s.%s", LOCKPRE
, s
);
* mlock(sys) create system lock
sprintf(lname
, "%s.%s", LOCKPRE
, sys
);
return(ulockf(lname
, (time_t) 24*3600 ) < 0 ? FAIL
: 0);