Calling remove_lockfile() does the wrong thing here, because it only
removes stale lockfiles. Here, the lockfile is not stale, because we know
that we own it. Therefore, we can remove it unconditionally.
{
if (lock_fd != -1) {
close(lock_fd);
+ unlink(lock_name);
+ lock_fd = -1;
}
- remove_lockfile(lock_name);
- lock_fd = -1;
}
/* Config may change, so caller responsible for notifying others if it
return fcntl(fd, F_SETLK, &l) == -1 ? errno : 0;
}
-/* Remove the lockfile with 'name'. */
+/* Remove the lockfile with 'name', if it is stale. Returns 0 if successful,
+ * otherwise a negative errno value if the lockfile is fresh or if it otherwise
+ * cannot be removed. */
int
remove_lockfile(const char *name)
{