* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)uucplock.c 5.1 (Berkeley) %G%";
* defs that come from uucp.h
#define SLCKTIME 28800 /* system/device timeout (LCK.. files) in seconds (8 hours) */
#define ASSERT(e, f, v) if (!(e)) {\
fprintf(stderr, "AERROR - (%s) ", "e");\
#define LOCKPRE "/usr/spool/uucp/LCK."
* This code is taken almost directly from uucp and follows the same
* conventions. This is important since uucp and tip should
* respect each others locks.
/* ulockf 3.2 10/26/79 11:40:29 */
* 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
, "/usr/spool/uucp/LTMP.%d", pid
);
if (onelock(pid
, tempfile
, file
) == -1) {
/* get status to check age of the lock file */
ret
= stat(file
, &stbuf
);
if ((ptime
- stbuf
.st_ctime
) < atime
) {
/* file not old enough to delete */
ret
= onelock(pid
, tempfile
, 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
++) {
if (name
== NULL
|| strcmp(name
, Lockfile
[i
]) == SAME
) {
* /usr/pjw/bin/recover - check pids to remove unnecessary locks
* isalock(name) returns 0 if the name 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
if (stat(name
, &xstat
) < 0)
if (xstat
.st_size
!= sizeof(int))
onelock(pid
, tempfile
, name
)
fd
= creat(tempfile
, 0444);
write(fd
,(char *)&pid
, sizeof(int));
if (link(tempfile
, name
) < 0) {
* 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) SLCKTIME
) < 0 ? FAIL
: 0);