cvs-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Cvs-cvs] ccvs/src ChangeLog commit.c lock.c lock.h


From: Derek Robert Price
Subject: [Cvs-cvs] ccvs/src ChangeLog commit.c lock.c lock.h
Date: Tue, 16 Sep 2008 21:52:17 +0000

CVSROOT:        /cvsroot/cvs
Module name:    ccvs
Changes by:     Derek Robert Price <dprice>     08/09/16 21:52:17

Modified files:
        src            : ChangeLog commit.c lock.c lock.h 

Log message:
        * commit.c (commit): Handle error return from lock_tree_promotably().
        * lock.c (lock_obtained, lock_wait): Move up to avoid prototypes.
        (set_lock): Likewise.  Accept bool in place of int. Update all callers.
        (lock_tree_promotably): Return recursion errors.
        * lock.h (lock_tree_promotably): Update prototype.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/ccvs/src/ChangeLog?cvsroot=cvs&r1=1.3589&r2=1.3590
http://cvs.savannah.gnu.org/viewcvs/ccvs/src/commit.c?cvsroot=cvs&r1=1.283&r2=1.284
http://cvs.savannah.gnu.org/viewcvs/ccvs/src/lock.c?cvsroot=cvs&r1=1.127&r2=1.128
http://cvs.savannah.gnu.org/viewcvs/ccvs/src/lock.h?cvsroot=cvs&r1=1.1&r2=1.2

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/cvs/ccvs/src/ChangeLog,v
retrieving revision 1.3589
retrieving revision 1.3590
diff -u -b -r1.3589 -r1.3590
--- ChangeLog   16 Sep 2008 21:00:09 -0000      1.3589
+++ ChangeLog   16 Sep 2008 21:52:15 -0000      1.3590
@@ -1,5 +1,11 @@
 2008-09-16  Derek R. Price  <address@hidden>
 
+       * commit.c (commit): Handle error return from lock_tree_promotably().
+       * lock.c (lock_obtained, lock_wait): Move up to avoid prototypes.
+       (set_lock): Likewise.  Accept bool in place of int. Update all callers.
+       (lock_tree_promotably): Return recursion errors.
+       * lock.h (lock_tree_promotably): Update prototype.
+
        * add.c (build_entry): Accept struct file_info in lieu of multiple
        args.  Change all callers.  Move to avoid prototypes.
        (add_directory): Move to avoid prototypes.

Index: commit.c
===================================================================
RCS file: /cvsroot/cvs/ccvs/src/commit.c,v
retrieving revision 1.283
retrieving revision 1.284
diff -u -b -r1.283 -r1.284
--- commit.c    15 Sep 2008 16:38:12 -0000      1.283
+++ commit.c    16 Sep 2008 21:52:16 -0000      1.284
@@ -683,7 +683,8 @@
 
     wrap_setup ();
 
-    lock_tree_promotably (argc, argv, local, W_LOCAL, aflag);
+    if (lock_tree_promotably (argc, argv, local, W_LOCAL, aflag))
+       error (1, 0, "correct above errors first!");
 
     /*
      * Set up the master update list and hard link list
@@ -706,10 +707,9 @@
     /*
      * Run the recursion processor to verify the files are all up-to-date
      */
-    err = start_recursion (check_fileproc, check_filesdoneproc,
+    if (start_recursion (check_fileproc, check_filesdoneproc,
                            check_direntproc, NULL, NULL, argc, argv, local,
-                           W_LOCAL, aflag, CVS_LOCK_NONE, NULL, 1, NULL);
-    if (err)
+                        W_LOCAL, aflag, CVS_LOCK_NONE, NULL, 1, NULL))
        error (1, 0, "correct above errors first!");
 
     /*

Index: lock.c
===================================================================
RCS file: /cvsroot/cvs/ccvs/src/lock.c,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -b -r1.127 -r1.128
--- lock.c      12 Sep 2008 19:55:27 -0000      1.127
+++ lock.c      16 Sep 2008 21:52:16 -0000      1.128
@@ -118,7 +118,6 @@
 };
 
 static void remove_locks (void);
-static int set_lock (struct lock *lock, int will_wait);
 static void clear_lock (struct lock *lock);
 static void set_lockers_name (struct stat *statp);
 static void unset_lockers_name (void);
@@ -487,6 +486,180 @@
 
 
 /*
+ * Print out a message when we obtain a lock.
+ */
+static void
+lock_obtained (const char *repos)
+{
+    time_t now;
+    char *msg;
+    struct tm *tm_p;
+
+    (void) time (&now);
+    tm_p = gmtime (&now);
+    msg = Xasprintf ("[%8.8s] obtained lock in %s",
+                    (tm_p ? asctime (tm_p) : ctime (&now)) + 11, repos);
+    error (0, 0, "%s", msg);
+    /* Call cvs_flusherr to ensure that the user sees this message as
+       soon as possible.  */
+    cvs_flusherr ();
+    free (msg);
+}
+
+
+
+/*
+ * Print out a message that the lock is still held, then sleep a while.
+ */
+static void
+lock_wait (const char *repos)
+{
+    time_t now;
+    char *msg;
+    struct tm *tm_p;
+
+    (void) time (&now);
+    tm_p = gmtime (&now);
+    msg = Xasprintf ("[%8.8s] waiting for %s's lock in %s",
+                    (tm_p ? asctime (tm_p) : ctime (&now)) + 11,
+                    lockers_name ? lockers_name : "unknown", repos);
+    error (0, 0, "%s", msg);
+    /* Call cvs_flusherr to ensure that the user sees this message as
+       soon as possible.  */
+    cvs_flusherr ();
+    free (msg);
+    (void)sleep (CVSLCKSLEEP);
+}
+
+
+
+/*
+ * Persistently tries to make the directory "lckdir", which serves as a
+ * lock.
+ *
+ * #ifdef CVS_FUDGELOCKS
+ * If the create time on the directory is greater than CVSLCKAGE
+ * seconds old, just try to remove the directory.
+ * #endif
+ *
+ */
+static int
+set_lock (struct lock *lock, bool will_wait)
+{
+    int waited;
+    long us;
+    struct stat sb;
+    mode_t omask;
+    char *masterlock;
+    int status;
+#ifdef CVS_FUDGELOCKS
+    time_t now;
+#endif
+
+    TRACE (TRACE_FLOW, "set_lock (%s, %d)",
+          lock->repository ? lock->repository : "(null)", will_wait);
+
+    masterlock = lock_name (lock->repository, lock->lockdirname);
+
+    /*
+     * Note that it is up to the callers of set_lock() to arrange for signal
+     * handlers that do the appropriate things, like remove the lock
+     * directory before they exit.
+     */
+    waited = 0;
+    us = 1;
+    for (;;)
+    {
+       status = -1;
+       omask = umask (cvsumask);
+       SIG_beginCrSect ();
+       if (CVS_MKDIR (masterlock, 0777) == 0)
+       {
+           lock->lockdir = masterlock;
+           SIG_endCrSect ();
+           status = L_OK;
+           if (waited)
+               lock_obtained (lock->repository);
+           goto after_sig_unblock;
+       }
+       SIG_endCrSect ();
+    after_sig_unblock:
+       (void) umask (omask);
+       if (status != -1)
+           goto done;
+
+       if (errno != EEXIST)
+       {
+           error (0, errno,
+                  "failed to create lock directory for `%s' (%s)",
+                  lock->repository, masterlock);
+           status = L_ERROR;
+           goto done;
+       }
+
+       /* Find out who owns the lock.  If the lock directory is
+          non-existent, re-try the loop since someone probably just
+          removed it (thus releasing the lock).  */
+       if (stat (masterlock, &sb) < 0)
+       {
+           if (existence_error (errno))
+               continue;
+
+           error (0, errno, "couldn't stat lock directory `%s'", masterlock);
+           status = L_ERROR;
+           goto done;
+       }
+
+#ifdef CVS_FUDGELOCKS
+       /*
+        * If the create time of the directory is more than CVSLCKAGE seconds
+        * ago, try to clean-up the lock directory, and if successful, just
+        * quietly retry to make it.
+        */
+       (void) time (&now);
+       if (now >= (sb.st_ctime + CVSLCKAGE))
+       {
+           if (CVS_RMDIR (masterlock) >= 0)
+               continue;
+       }
+#endif
+
+       /* set the lockers name */
+       set_lockers_name (&sb);
+
+       /* if he wasn't willing to wait, return an error */
+       if (!will_wait)
+       {
+           status = L_LOCKED;
+           goto done;
+       }
+
+       /* if possible, try a very short sleep without a message */
+       if (!waited && us < 1000)
+       {
+           us += us;
+           {
+               struct timespec ts;
+               ts.tv_sec = 0;
+               ts.tv_nsec = us * 1000;
+               (void)nanosleep (&ts, NULL);
+               continue;
+           }
+       }
+
+       lock_wait (lock->repository);
+       waited = 1;
+    }
+
+done:
+    if (!lock->lockdir)
+       free (masterlock);
+    return status;
+}
+
+
+
+/*
  * Create a lock file for readers
  */
 int
@@ -514,7 +687,7 @@
     global_readlock.free_repository = true;
 
     /* get the lock dir for our own */
-    if (set_lock (&global_readlock, 1) != L_OK)
+    if (set_lock (&global_readlock, true) != L_OK)
     {
        error (0, 0, "failed to obtain dir lock in repository `%s'",
               xrepository);
@@ -730,7 +903,7 @@
     }
 
     /* make sure the lock dir is ours (not necessarily unique to us!) */
-    status = set_lock (lock, 0);
+    status = set_lock (lock, false);
     if (status == L_OK)
     {
        /* we now own a promotable lock - make sure there are no others */
@@ -840,54 +1013,6 @@
 
 
 
-/*
- * Print out a message that the lock is still held, then sleep a while.
- */
-static void
-lock_wait (const char *repos)
-{
-    time_t now;
-    char *msg;
-    struct tm *tm_p;
-
-    (void) time (&now);
-    tm_p = gmtime (&now);
-    msg = Xasprintf ("[%8.8s] waiting for %s's lock in %s",
-                    (tm_p ? asctime (tm_p) : ctime (&now)) + 11,
-                    lockers_name ? lockers_name : "unknown", repos);
-    error (0, 0, "%s", msg);
-    /* Call cvs_flusherr to ensure that the user sees this message as
-       soon as possible.  */
-    cvs_flusherr ();
-    free (msg);
-    (void)sleep (CVSLCKSLEEP);
-}
-
-
-
-/*
- * Print out a message when we obtain a lock.
- */
-static void
-lock_obtained (const char *repos)
-{
-    time_t now;
-    char *msg;
-    struct tm *tm_p;
-
-    (void) time (&now);
-    tm_p = gmtime (&now);
-    msg = Xasprintf ("[%8.8s] obtained lock in %s",
-                    (tm_p ? asctime (tm_p) : ctime (&now)) + 11, repos);
-    error (0, 0, "%s", msg);
-    /* Call cvs_flusherr to ensure that the user sees this message as
-       soon as possible.  */
-    cvs_flusherr ();
-    free (msg);
-}
-
-
-
 static int
 lock_list_promotably (List *list)
 {
@@ -999,132 +1124,6 @@
 
 
 /*
- * Persistently tries to make the directory "lckdir", which serves as a
- * lock.
- *
- * #ifdef CVS_FUDGELOCKS
- * If the create time on the directory is greater than CVSLCKAGE
- * seconds old, just try to remove the directory.
- * #endif
- *
- */
-static int
-set_lock (struct lock *lock, int will_wait)
-{
-    int waited;
-    long us;
-    struct stat sb;
-    mode_t omask;
-    char *masterlock;
-    int status;
-#ifdef CVS_FUDGELOCKS
-    time_t now;
-#endif
-
-    TRACE (TRACE_FLOW, "set_lock (%s, %d)",
-          lock->repository ? lock->repository : "(null)", will_wait);
-
-    masterlock = lock_name (lock->repository, lock->lockdirname);
-
-    /*
-     * Note that it is up to the callers of set_lock() to arrange for signal
-     * handlers that do the appropriate things, like remove the lock
-     * directory before they exit.
-     */
-    waited = 0;
-    us = 1;
-    for (;;)
-    {
-       status = -1;
-       omask = umask (cvsumask);
-       SIG_beginCrSect ();
-       if (CVS_MKDIR (masterlock, 0777) == 0)
-       {
-           lock->lockdir = masterlock;
-           SIG_endCrSect ();
-           status = L_OK;
-           if (waited)
-               lock_obtained (lock->repository);
-           goto after_sig_unblock;
-       }
-       SIG_endCrSect ();
-    after_sig_unblock:
-       (void) umask (omask);
-       if (status != -1)
-           goto done;
-
-       if (errno != EEXIST)
-       {
-           error (0, errno,
-                  "failed to create lock directory for `%s' (%s)",
-                  lock->repository, masterlock);
-           status = L_ERROR;
-           goto done;
-       }
-
-       /* Find out who owns the lock.  If the lock directory is
-          non-existent, re-try the loop since someone probably just
-          removed it (thus releasing the lock).  */
-       if (stat (masterlock, &sb) < 0)
-       {
-           if (existence_error (errno))
-               continue;
-
-           error (0, errno, "couldn't stat lock directory `%s'", masterlock);
-           status = L_ERROR;
-           goto done;
-       }
-
-#ifdef CVS_FUDGELOCKS
-       /*
-        * If the create time of the directory is more than CVSLCKAGE seconds
-        * ago, try to clean-up the lock directory, and if successful, just
-        * quietly retry to make it.
-        */
-       (void) time (&now);
-       if (now >= (sb.st_ctime + CVSLCKAGE))
-       {
-           if (CVS_RMDIR (masterlock) >= 0)
-               continue;
-       }
-#endif
-
-       /* set the lockers name */
-       set_lockers_name (&sb);
-
-       /* if he wasn't willing to wait, return an error */
-       if (!will_wait)
-       {
-           status = L_LOCKED;
-           goto done;
-       }
-
-       /* if possible, try a very short sleep without a message */
-       if (!waited && us < 1000)
-       {
-           us += us;
-           {
-               struct timespec ts;
-               ts.tv_sec = 0;
-               ts.tv_nsec = us * 1000;
-               (void)nanosleep (&ts, NULL);
-               continue;
-           }
-       }
-
-       lock_wait (lock->repository);
-       waited = 1;
-    }
-
-done:
-    if (!lock->lockdir)
-       free (masterlock);
-    return status;
-}
-
-
-
-/*
  * Clear master lock.
  *
  * INPUTS
@@ -1185,9 +1184,13 @@
 
 
 
-void
+/* Return recursion errors, but exit on locking errors.
+ */
+int
 lock_tree_promotably (int argc, char **argv, int local, int which, int aflag)
 {
+    int err;
+
     TRACE (TRACE_FUNCTION, "lock_tree_promotably (%d, argv, %d, %d, %d)",
           argc, local, which, aflag);
 
@@ -1196,14 +1199,16 @@
      * the dirs
      */
     lock_tree_list = getlist ();
-    start_recursion
-       (NULL, lock_filesdoneproc,
-        NULL, NULL, NULL, argc,
-        argv, local, which, aflag, CVS_LOCK_NONE,
-        NULL, 0, NULL );
+    err = start_recursion (NULL, lock_filesdoneproc, NULL, NULL, NULL, argc,
+                          argv, local, which, aflag, CVS_LOCK_NONE, NULL, 0,
+                          NULL);
+    if (err) return err;
+
     sortlist (lock_tree_list, fsortcmp);
     if (lock_list_promotably (lock_tree_list) != 0)
        error (1, 0, "lock failed - giving up");
+
+    return 0;
 }
 
 
@@ -1247,7 +1252,7 @@
        {
            FILE *fp;
 
-           if (set_lock (&global_writelock, 1) != L_OK)
+           if (set_lock (&global_writelock, true) != L_OK)
                error (1, 0, "failed to obtain write lock in repository `%s'",
                       repository);
 
@@ -1322,7 +1327,7 @@
     lock->free_repository = true;
 
     /* get the lock dir for our own */
-    if (set_lock (lock, 1) != L_OK)
+    if (set_lock (lock, true) != L_OK)
     {
        if (!really_quiet)
            error (0, 0,

Index: lock.h
===================================================================
RCS file: /cvsroot/cvs/ccvs/src/lock.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- lock.h      12 Sep 2007 13:07:33 -0000      1.1
+++ lock.h      16 Sep 2008 21:52:16 -0000      1.2
@@ -23,9 +23,10 @@
 void Simple_Lock_Cleanup (void);
 void Lock_Cleanup (void);
 
-/* Writelock an entire subtree, well the part specified by ARGC, ARGV, LOCAL,
-   and AFLAG, anyway.  */
-void lock_tree_promotably (int argc, char **argv, int local, int which,
+/* Recursively aquire a promotable read lock for the subtree specified by ARGC,
+ * ARGV, LOCAL, and AFLAG.
+ */
+int lock_tree_promotably (int argc, char **argv, int local, int which,
                           int aflag);
 
 /* See lock.c for description.  */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]