[distcc] Re: distcc for Cygwin?
Martin Pool
mbp at sourcefrog.net
Thu Aug 1 04:11:02 GMT 2002
Marco, could you try this patch?
--- where.c.~1.25.~ 2002-07-24 21:31:31.000000000 +1000
+++ where.c 2002-08-01 21:02:40.000000000 +1000
@@ -110,6 +110,35 @@ static char * dcc_make_lock_filename(con
return buf;
}
+
+/**
+ * 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.
+ **/
+static int sys_lock(int fd)
+{
+#if defined(F_SETLK)
+ struct flock lockparam;
+
+ lockparam.l_type = F_WRLCK;
+ lockparam.l_whence = SEEK_SET;
+ lockparam.l_start = 0;
+ lockparam.l_len = 0; /* whole file */
+
+ return fcntl(fd, F_SETLK, &lockparam);
+#elif defined(HAVE_FLOCK)
+ return flock(fd, LOCK_EX|LOCK_NB);
+#elif defined(HAVE_LOCKF)
+ return lockf(fd, F_TLOCK, 0);
+#else
+# error "No supported lock method. Please port this code."
+#endif
+}
+
+
static int dcc_try_lock_host(const char *host, int iter)
{
const char *tempdir;
@@ -127,13 +156,8 @@ static int dcc_try_lock_host(const char
goto bomb;
}
-#if defined(HAVE_FLOCK)
- ret = flock(fd, LOCK_EX|LOCK_NB);
-#elif defined(HAVE_LOCKF)
- ret = lockf(fd, F_TLOCK, 0);
-#else
-# error "No supported lock method. Please port this code."
-#endif
+ ret = sys_lock(fd);
+
if (ret != -1) {
rs_trace("locked %s", fname);
free(fname);
--
Martin
More information about the distcc
mailing list