From: Ben Pfaff Date: Wed, 11 Mar 2009 21:43:53 +0000 (-0700) Subject: cfg: Fix cfg_unlock() to remove the lockfile unconditionally. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9673d1eb0a90cba206c654dffb5005abe5bc43ce;p=openvswitch 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. --- 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) {