CVS update: /ccvs/src/

[email protected] 27 Apr 2005 21:57:17 -0000
Newsgroups gmane.comp.version-control.cvs.cvs
Message-ID <[email protected]>
User: dprice  
Date: 05/04/27 14:57:17

Modified:
 /ccvs/src/
  ChangeLog, lock.c

Log:
 * lock.c (struct lock): Store lockdir name.
 (masterlock): Remove global.
 (remove_lock_files, clear_lock, set_lock): Update to compensate.

File Changes:

Directory: /ccvs/src/
=====================

File [changed]: ChangeLog
Url: https://ccvs.cvshome.org/source/browse/ccvs/src/ChangeLog?r1=1.3177&r2=1.3178
Delta lines:  +6 -0
-------------------
--- ChangeLog	25 Apr 2005 21:42:44 -0000	1.3177
+++ ChangeLog	27 Apr 2005 21:57:14 -0000	1.3178
@@ -1,3 +1,9 @@
+2005-04-27  Derek Price  <[email protected]>
+
+	* lock.c (struct lock): Store lockdir name.
+	(masterlock): Remove global.
+	(remove_lock_files, clear_lock, set_lock): Update to compensate.
+
 2005-04-25  Mark D. Baushke  <[email protected]>
 
 	* server.c: Add support for <pam/pam_appl.h> to allow

File [changed]: lock.c
Url: https://ccvs.cvshome.org/source/browse/ccvs/src/lock.c?r1=1.110&r2=1.111
Delta lines:  +34 -28
---------------------
--- lock.c	22 Mar 2005 13:19:57 -0000	1.110
+++ lock.c	27 Apr 2005 21:57:14 -0000	1.111
@@ -88,8 +88,9 @@
     char *file2;
 #endif /* LOCK_COMPATIBILITY */
 
-    /* Do we have a lock named CVSLCK?  */
-    int have_lckdir;
+    /* The lock dir (usually CVSLCK), if we are currently holding it.  */
+    char *lockdir;
+
     /* Note there is no way of knowing whether the readlock and writelock
        exist.  The code which sets the locks doesn't use SIG_beginCrSect
        to set a flag like we do for CVSLCK.  */
@@ -113,9 +114,6 @@
 /* Malloc'd array specifying name of a promotablelock within a directory.
    Or NULL if none.  */
 static char *promotablelock;
-/* Malloc'd array specifying the name of a CVSLCK file (absolute pathname).
-   Will always be non-NULL in the cases where it is used.  */
-static char *masterlock;
 static List *locklist;
 
 #define L_OK		0		/* success */
@@ -313,15 +311,14 @@
     }
 #endif /* LOCK_COMPATIBILITY */
 
-    if (lock->have_lckdir)
+    if (lock->lockdir)
     {
-	char *tmp = lock_name (lock->repository, CVSLCK);
 	SIG_beginCrSect ();
-	if (CVS_RMDIR (tmp) < 0)
-	    error (0, errno, "failed to remove lock dir %s", tmp);
-	lock->have_lckdir = 0;
+	if (CVS_RMDIR (lock->lockdir) < 0)
+	    error (0, errno, "failed to remove lock dir %s", lock->lockdir);
+	free (lock->lockdir);
+	lock->lockdir = NULL;
 	SIG_endCrSect ();
-	free (tmp);
     }
 
     /* And free the repository string.  We don't really have to set the
@@ -988,6 +985,8 @@
     long us;
     struct stat sb;
     mode_t omask;
+    char *masterlock;
+    int status;
 #ifdef CVS_FUDGELOCKS
     time_t now;
 #endif
@@ -995,8 +994,6 @@
     TRACE (TRACE_FLOW, "set_lock (%s, %d)",
 	   lock->repository ? lock->repository : "(null)", will_wait);
 
-    if (masterlock != NULL)
-	free (masterlock);
     masterlock = lock_name (lock->repository, CVSLCK);
 
     /*
@@ -1006,33 +1003,33 @@
      */
     waited = 0;
     us = 1;
-    lock->have_lckdir = 0;
     for (;;)
     {
-	int status = -1;
+	status = -1;
 	omask = umask (cvsumask);
 	SIG_beginCrSect ();
 	if (CVS_MKDIR (masterlock, 0777) == 0)
 	{
-	    lock->have_lckdir = 1;
+	    lock->lockdir = masterlock;
 	    SIG_endCrSect ();
 	    status = L_OK;
 	    if (waited)
 	        lock_obtained (lock->repository);
-	    goto out;
+	    goto after_sig_unblock;
 	}
 	SIG_endCrSect ();
-      out:
+    after_sig_unblock:
 	(void) umask (omask);
 	if (status != -1)
-	    return status;
+	    goto done;
 
 	if (errno != EEXIST)
 	{
 	    error (0, errno,
 		   "failed to create lock directory for `%s' (%s)",
 		   lock->repository, masterlock);
-	    return (L_ERROR);
+	    status = L_ERROR;
+	    goto done;
 	}
 
 	/* Find out who owns the lock.  If the lock directory is
@@ -1044,7 +1041,8 @@
 		continue;
 
 	    error (0, errno, "couldn't stat lock directory `%s'", masterlock);
-	    return (L_ERROR);
+	    status = L_ERROR;
+	    goto done;
 	}
 
 #ifdef CVS_FUDGELOCKS
@@ -1066,7 +1064,10 @@
 
 	/* if he wasn't willing to wait, return an error */
 	if (!will_wait)
-	    return (L_LOCKED);
+	{
+	    status = L_LOCKED;
+	    goto done;
+	}
 
 	/* if possible, try a very short sleep without a message */
 	if (!waited && us < 1000)
@@ -1084,21 +1085,26 @@
 	lock_wait (lock->repository);
 	waited = 1;
     }
+
+done:
+    if (!lock->lockdir)
+	free (masterlock);
+    return status;
 }
 
 
 
 /*
- * Clear master lock.  We don't have to recompute the lock name since
- * clear_lock is never called except after a successful set_lock().
+ * Clear master lock.
  */
 static void
 clear_lock (struct lock *lock)
 {
     SIG_beginCrSect ();
-    if (CVS_RMDIR (masterlock) < 0)
-	error (0, errno, "failed to remove lock dir `%s'", masterlock);
-    lock->have_lckdir = 0;
+    if (CVS_RMDIR (lock->lockdir) < 0)
+	error (0, errno, "failed to remove lock dir `%s'", lock->lockdir);
+    free (lock->lockdir);
+    lock->lockdir = NULL;
     SIG_endCrSect ();
 }
 
@@ -1123,7 +1129,7 @@
 #ifdef LOCK_COMPATIBILITY
     ((struct lock *)p->data)->file2 = NULL;
 #endif /* LOCK_COMPATIBILITY */
-    ((struct lock *)p->data)->have_lckdir = 0;
+    ((struct lock *)p->data)->lockdir = NULL;
     ((struct lock *)p->data)->free_repository = 0;
 
     /* FIXME-KRP: this error condition should not simply be passed by. */