* Stuff to do version 7 style locking.
static char *SccsId
= "@(#)lock.c 1.1 %G%";
char *maillock
= ".lock"; /* Lock suffix for mailname */
char *lockname
= "/usr/spool/mail/tmXXXXXX";
char locktmp
[30]; /* Usable lock temporary */
static char curlock
[50]; /* Last used name of lock */
static int locked
; /* To note that we locked it */
* Lock the specified mail file by setting the file mailfile.lock.
* We must, of course, be careful to remove the lock file by a call
* to unlock before we stop. The algorithm used here is to see if
* the lock exists, and if it does, to check its modify time. If it
* is older than 30 seconds, we assume error and set our own file.
* Otherwise, we wait for 5 seconds and try again.
printf("Locked = %d\n", locked
);
strcat(curlock
, maillock
);
strcpy(locktmp
, lockname
);
f
= lock1(locktmp
, curlock
);
if (stat(curlock
, &sbuf
) < 0)
if (curtime
< sbuf
.st_ctime
+ 30) {
* Remove the mail lock, and note that we no longer
* Attempt to set the lock by creating the temporary file,
* then doing a link/unlink. If it fails, return -1 else 0
if (link(tempfile
, name
) < 0) {