BSD 4_3 release
[unix-history] / usr / src / usr.bin / tip / uucplock.c
index 3ad1dae..d4d94f1 100644 (file)
@@ -1,11 +1,20 @@
-/*     uucplock.c      4.2     81/11/20        */
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)uucplock.c 5.2 (Berkeley) 11/29/85";
+#endif not lint
+
 /*
  * defs that come from uucp.h
  */
 /*
  * defs that come from uucp.h
  */
-#define NAMESIZE 15
+#define NAMESIZE 32
 #define FAIL -1
 #define SAME 0
 #define FAIL -1
 #define SAME 0
-#define SLCKTIME 5400  /* system/device timeout (LCK.. files) in seconds */
+#define SLCKTIME 28800 /* system/device timeout (LCK.. files) in seconds (8 hours) */
 #define ASSERT(e, f, v) if (!(e)) {\
        fprintf(stderr, "AERROR - (%s) ", "e");\
        fprintf(stderr, f, v);\
 #define ASSERT(e, f, v) if (!(e)) {\
        fprintf(stderr, "AERROR - (%s) ", "e");\
        fprintf(stderr, f, v);\
@@ -63,16 +72,16 @@ ulockf(file, atime)
                        time(&ptime);
                        if ((ptime - stbuf.st_ctime) < atime) {
                                /* file not old enough to delete */
                        time(&ptime);
                        if ((ptime - stbuf.st_ctime) < atime) {
                                /* file not old enough to delete */
-                               return(FAIL);
+                               return (FAIL);
                        }
                }
                ret = unlink(file);
                ret = onelock(pid, tempfile, file);
                if (ret != 0)
                        }
                }
                ret = unlink(file);
                ret = onelock(pid, tempfile, file);
                if (ret != 0)
-                       return(FAIL);
+                       return (FAIL);
        }
        stlock(file);
        }
        stlock(file);
-       return(0);
+       return (0);
 }
 
 #define MAXLOCKS 10    /* maximum number of lock files */
 }
 
 #define MAXLOCKS 10    /* maximum number of lock files */
@@ -124,14 +133,12 @@ rmlock(name)
        for (i = 0; i < Nlocks; i++) {
                if (Lockfile[i] == NULL)
                        continue;
        for (i = 0; i < Nlocks; i++) {
                if (Lockfile[i] == NULL)
                        continue;
-               if (name == NULL
-               || strcmp(name, Lockfile[i]) == SAME) {
+               if (name == NULL || strcmp(name, Lockfile[i]) == SAME) {
                        unlink(Lockfile[i]);
                        free(Lockfile[i]);
                        Lockfile[i] = NULL;
                }
        }
                        unlink(Lockfile[i]);
                        free(Lockfile[i]);
                        Lockfile[i] = NULL;
                }
        }
-       return;
 }
 
 /*
 }
 
 /*
@@ -153,30 +160,30 @@ isalock(name)
 {
        struct stat xstat;
 
 {
        struct stat xstat;
 
-       if(stat(name,&xstat)<0)
-               return(0);
-       if(xstat.st_size!=sizeof(int))
-               return(0);
-       return(1);
+       if (stat(name, &xstat) < 0)
+               return (0);
+       if (xstat.st_size != sizeof(int))
+               return (0);
+       return (1);
 }
 
 static
 }
 
 static
-onelock(pid,tempfile,name)
-       char *tempfile,*name;
+onelock(pid, tempfile, name)
+       char *tempfile, *name;
 {
        int fd;
 
 {
        int fd;
 
-       fd=creat(tempfile,0444);
-       if(fd<0)
-               return(-1);
-       write(fd,(char *) &pid,sizeof(int));
+       fd = creat(tempfile, 0444);
+       if (fd < 0)
+               return (-1);
+       write(fd,(char *)&pid, sizeof(int));
        close(fd);
        close(fd);
-       if(link(tempfile,name)<0) {
+       if (link(tempfile, name) < 0) {
                unlink(tempfile);
                unlink(tempfile);
-               return(-1);
+               return (-1);
        }
        unlink(tempfile);
        }
        unlink(tempfile);
-       return(0);
+       return (0);
 }
 
 /***
 }
 
 /***
@@ -207,5 +214,5 @@ mlock(sys)
 {
        char lname[30];
        sprintf(lname, "%s.%s", LOCKPRE, sys);
 {
        char lname[30];
        sprintf(lname, "%s.%s", LOCKPRE, sys);
-       return(ulockf(lname, (time_t) SLCKTIME ) < 0 ? FAIL : 0);
+       return (ulockf(lname, (time_t) SLCKTIME ) < 0 ? FAIL : 0);
 }
 }