From 9673d1eb0a90cba206c654dffb5005abe5bc43ce Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 11 Mar 2009 14:43:53 -0700 Subject: [PATCH] cfg: Fix cfg_unlock() to remove the lockfile unconditionally. 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. --- lib/cfg.c | 4 ++-- lib/lockfile.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/cfg.c b/lib/cfg.c index 4a1e0a03..ae07356b 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -255,9 +255,9 @@ cfg_unlock(void) { 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 diff --git a/lib/lockfile.c b/lib/lockfile.c index 031f2453..370567c9 100644 --- a/lib/lockfile.c +++ b/lib/lockfile.c @@ -28,7 +28,9 @@ fcntl_lock(int fd) 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) { -- 2.30.2