diff options
-rw-r--r-- | ctdb/server/ctdb_mutex_fcntl_helper.c | 30 | ||||
-rwxr-xr-x | ctdb/tests/UNIT/cunit/cluster_mutex_002.sh | 2 |
2 files changed, 26 insertions, 6 deletions
diff --git a/ctdb/server/ctdb_mutex_fcntl_helper.c b/ctdb/server/ctdb_mutex_fcntl_helper.c index 2f9e32580c2..07f111a0d6b 100644 --- a/ctdb/server/ctdb_mutex_fcntl_helper.c +++ b/ctdb/server/ctdb_mutex_fcntl_helper.c @@ -225,6 +225,7 @@ static void lock_io_check_loop(struct tevent_req *subreq) req, struct lock_io_check_state); bool status; struct stat sb; + int fd = -1; int ret; status = tevent_wakeup_recv(subreq); @@ -234,7 +235,18 @@ static void lock_io_check_loop(struct tevent_req *subreq) fprintf(stderr, "%s: tevent_wakeup_recv() failed\n", progname); } - ret = stat(state->lock_file, &sb); + fd = open(state->lock_file, O_RDWR); + if (fd == -1) { + fprintf(stderr, + "%s: " + "lock lost - lock file \"%s\" open failed (ret=%d)\n", + progname, + state->lock_file, + errno); + goto done; + } + + ret = fstat(fd, &sb); if (ret != 0) { fprintf(stderr, "%s: " @@ -242,8 +254,7 @@ static void lock_io_check_loop(struct tevent_req *subreq) progname, state->lock_file, errno); - tevent_req_done(req); - return; + goto done; } if (sb.st_ino != state->inode) { @@ -251,10 +262,11 @@ static void lock_io_check_loop(struct tevent_req *subreq) "%s: lock lost - lock file \"%s\" inode changed\n", progname, state->lock_file); - tevent_req_done(req); - return; + goto done; } + close(fd); + subreq = tevent_wakeup_send( state, state->ev, @@ -263,6 +275,14 @@ static void lock_io_check_loop(struct tevent_req *subreq) return; } tevent_req_set_callback(subreq, lock_io_check_loop, req); + + return; + +done: + if (fd != -1) { + close(fd); + } + tevent_req_done(req); } static bool lock_io_check_recv(struct tevent_req *req, int *perr) diff --git a/ctdb/tests/UNIT/cunit/cluster_mutex_002.sh b/ctdb/tests/UNIT/cunit/cluster_mutex_002.sh index 65d57c3f2b1..c21d1d38f33 100755 --- a/ctdb/tests/UNIT/cunit/cluster_mutex_002.sh +++ b/ctdb/tests/UNIT/cunit/cluster_mutex_002.sh @@ -88,7 +88,7 @@ unit_test cluster_mutex_test lock-file-wait-recheck-unlock \ test_case "Recheck on, lock file removed" ok <<EOF LOCK -ctdb_mutex_fcntl_helper: lock lost - lock file "${lockfile}" check failed (ret=2) +ctdb_mutex_fcntl_helper: lock lost - lock file "${lockfile}" open failed (ret=2) LOST EOF unit_test cluster_mutex_test lock-file-removed "$helper 5" "$lockfile" |