}
if (slept > staleness_limit) {
if (str_eq(content, initial_content)) {
- // The lock seems to be stale -- break it.
+ // The lock seems to be stale -- break it and try again.
cc_log("lockfile_acquire: breaking %s", lockfile);
- // Try to acquire path.lock.lock:
- if (lockfile_acquire(lockfile, staleness_limit)) {
- lockfile_release(path); // Remove path.lock
- lockfile_release(lockfile); // Remove path.lock.lock
- to_sleep = 1000;
- slept = 0;
- continue;
+ if (tmp_unlink(lockfile) != 0) {
+ cc_log("Failed to unlink %s: %s", lockfile, strerror(errno));
+ goto out;
}
+ to_sleep = 1000;
+ slept = 0;
+ continue;
}
cc_log("lockfile_acquire: gave up acquiring %s", lockfile);
goto out;
{
char* lockfile = format("%s.lock", path);
cc_log("Releasing lock %s", lockfile);
+ if (tmp_unlink(lockfile) != 0) {
+ cc_log("Failed to unlink %s: %s", lockfile, strerror(errno));
+ }
tmp_unlink(lockfile);
free(lockfile);
}
#if defined(_WIN32) || defined(__CYGWIN__)
create_file("test.lock", "foo");
- create_file("test.lock.lock", "foo");
#else
CHECK_INT_EQ(0, symlink("foo", "test.lock"));
- CHECK_INT_EQ(0, symlink("foo", "test.lock.lock"));
#endif
CHECK(lockfile_acquire("test", 1000));
#endif
CHECK(p);
CHECK(!str_eq(p, "foo"));
- CHECK(!path_exists("test.lock.lock"));
free(p);
}