[distcc] hpux locking

Martin Pool mbp at sourcefrog.net
Fri Feb 28 22:10:45 GMT 2003


Actually this would be better.

Index: lock.c
===================================================================
RCS file: /data/cvs/distcc/src/lock.c,v
retrieving revision 1.23
diff -u -u -p -r1.23 lock.c
--- lock.c	25 Feb 2003 00:28:56 -0000	1.23
+++ lock.c	28 Feb 2003 22:10:50 -0000
@@ -28,7 +28,7 @@
 /**
  * @file
  *
- * Manage lockfiles.
+ * @brief Manage lockfiles.
  *
  * distcc uses a simple disk-based lockfile system to keep track of how many
  * jobs are queued on various machines.  These locks might be used for
@@ -102,7 +102,7 @@ static char * dcc_make_lock_filename(con
     if (host->mode == DCC_MODE_LOCAL) {
         asprintf(&buf, "%s/lock_%s_localhost_%d", tempdir, lockname, iter);
     } else if (host->mode == DCC_MODE_TCP) {
-        asprintf(&buf, "%s/lock_%s_tcp_%s:%d_%d", tempdir, lockname, host->hostname,
+        asprintf(&buf, "%s/lock_%s_tcp_%s_%d_%d", tempdir, lockname, host->hostname,
                  host->port, iter);
     } else if (host->mode == DCC_MODE_SSH) {
         asprintf(&buf, "%s/lock_%s_ssh_%s_%d", tempdir, lockname, host->hostname, iter);
@@ -121,8 +121,8 @@ static char * dcc_make_lock_filename(con
  * Get an exclusive, non-blocking lock on a file using whatever method
  * is available on this system.
  *
- * @return 0 if we got the lock; -1 with EAGAIN if the file is already
- * locked.
+ * @retval 0 if we got the lock
+ * @retval -1 with errno set if the file is already locked.
  **/
 static int sys_lock(int fd, int block)
 {
@@ -204,17 +204,17 @@ int dcc_lock_host(const char *lockname,
     }        
 
     if (sys_lock(*lock_fd, block) == 0) {
-        rs_trace("locked %s", fname);
+        /* TODO: Print better readable form of hostdef. */
+        rs_trace("got %s lock on %s slot %d", lockname, host->hostname, slot);
         free(fname);
         return 0;
     } else {
         switch (errno) {
-#ifdef EWOULDBLOCK
+#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
         case EWOULDBLOCK:
 #endif
-#if defined(EAGAIN) && EAGAIN != EWOULDBLOCK
         case EAGAIN:
-#endif
+        case EACCES: /* HP-UX gives this for exclusion */
             rs_trace("%s is busy", fname);
             ret = EXIT_BUSY;
             break;
@@ -228,7 +228,4 @@ int dcc_lock_host(const char *lockname,
         free(fname);
         return ret;
     }
-
-    /* TODO: Print better readable form of hostdef. */
-    rs_trace("got %s lock on %s slot %d", lockname, host->hostname, slot);
 }


-- 
Martin


More information about the distcc mailing list