-static
-ulockf(file, atime)
- char *file;
- time_t atime;
-{
- struct stat stbuf;
- time_t ptime;
- int ret;
- static int pid = -1;
- static char tempfile[NAMESIZE];
-
- if (pid < 0) {
- pid = getpid();
- sprintf(tempfile, "/usr/spool/uucp/LTMP.%d", pid);
- }
- if (onelock(pid, tempfile, file) == -1) {
- /* lock file exists */
- /* get status to check age of the lock file */
- ret = stat(file, &stbuf);
- if (ret != -1) {
- time(&ptime);
- if ((ptime - stbuf.st_ctime) < atime) {
- /* file not old enough to delete */
- return (FAIL);
- }
- }
- ret = unlink(file);
- ret = onelock(pid, tempfile, file);
- if (ret != 0)
- return (FAIL);
- }
- stlock(file);
- return (0);
-}
-
-#define MAXLOCKS 10 /* maximum number of lock files */
-char *Lockfile[MAXLOCKS];
-int Nlocks = 0;
-
-/***
- * stlock(name) put name in list of lock files
- * char *name;
- *
- * return codes: none
- */
-
-static
-stlock(name)
- char *name;
-{
- char *p;
- extern char *calloc();
- int i;
-
- for (i = 0; i < Nlocks; i++) {
- if (Lockfile[i] == NULL)
- break;
- }
- ASSERT(i < MAXLOCKS, "TOO MANY LOCKS %d", i);
- if (i >= Nlocks)
- i = Nlocks++;
- p = calloc(strlen(name) + 1, sizeof (char));
- ASSERT(p != NULL, "CAN NOT ALLOCATE FOR %s", name);
- strcpy(p, name);
- Lockfile[i] = p;
- return;
-}