]> diplodocus.org Git - nmh/commitdiff
sbr/lock_file.c: Move static variables into their functions.
authorRalph Corderoy <ralph@inputplus.co.uk>
Fri, 21 Apr 2017 23:48:47 +0000 (00:48 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Fri, 21 Apr 2017 23:48:47 +0000 (00:48 +0100)
A couple of file-scoped statc ints were the typical "if this function is
being called for the first time" flags.  Move each into their respective
functions.  Make them bools.  Name them so the initial value is zero,
thus placing them in BSS.

sbr/lock_file.c

index cac80c1..aed11a1 100644 (file)
@@ -73,15 +73,9 @@ struct lock {
 
 enum locktype { FCNTL_LOCKING, FLOCK_LOCKING, LOCKF_LOCKING, DOT_LOCKING };
 
 
 enum locktype { FCNTL_LOCKING, FLOCK_LOCKING, LOCKF_LOCKING, DOT_LOCKING };
 
-/*
- * Flags to indicate whether we've initialized the lock types, and
- * our saved lock types
- */
-static int datalockinit = 0;
-static int spoollockinit = 0;
+/* Our saved lock types. */
 static enum locktype datalocktype, spoollocktype;
 
 static enum locktype datalocktype, spoollocktype;
 
-
 /* top of list containing all open locks */
 static struct lock *l_top = NULL;
 
 /* top of list containing all open locks */
 static struct lock *l_top = NULL;
 
@@ -117,17 +111,18 @@ static int lockit (struct lockinfo *);
 int
 lkopendata(const char *file, int access, mode_t mode, int *failed_to_lock)
 {
 int
 lkopendata(const char *file, int access, mode_t mode, int *failed_to_lock)
 {
-    if (! datalockinit) {
-       char *cp = context_find("datalocking");
+    static bool deja_vu;
 
 
-       if (cp) {
-           datalocktype = init_locktype(cp);
+    if (!deja_vu) {
+        char *dl;
+
+        deja_vu = true;
+       if ((dl = context_find("datalocking"))) {
+           datalocktype = init_locktype(dl);
        } else {
            /* We default to fcntl locking for data files */
            datalocktype = FCNTL_LOCKING;
        }
        } else {
            /* We default to fcntl locking for data files */
            datalocktype = FCNTL_LOCKING;
        }
-
-       datalockinit = 1;
     }
 
     return lkopen(file, access, mode, datalocktype, failed_to_lock);
     }
 
     return lkopen(file, access, mode, datalocktype, failed_to_lock);
@@ -140,10 +135,11 @@ lkopendata(const char *file, int access, mode_t mode, int *failed_to_lock)
 
 int lkopenspool(const char *file, int access, mode_t mode, int *failed_to_lock)
 {
 
 int lkopenspool(const char *file, int access, mode_t mode, int *failed_to_lock)
 {
-    if (! spoollockinit) {
-       spoollocktype = init_locktype(spoollocking);
+    static bool deja_vu;
 
 
-       spoollockinit = 1;
+    if (!deja_vu) {
+       deja_vu = true;
+        spoollocktype = init_locktype(spoollocking);
     }
 
     return lkopen(file, access, mode, spoollocktype, failed_to_lock);
     }
 
     return lkopen(file, access, mode, spoollocktype, failed_to_lock);