diff --git a/common/dotlock.c b/common/dotlock.c index da3f09e30..4320c547e 100644 --- a/common/dotlock.c +++ b/common/dotlock.c @@ -1012,6 +1012,14 @@ dotlock_destroy (dotlock_t h) } +/* Return true if H has been taken. */ +int +dotlock_is_locked (dotlock_t h) +{ + return h && !!h->locked; +} + + #ifdef HAVE_POSIX_SYSTEM /* Unix specific code of make_dotlock. Returns 0 on success and -1 on @@ -1250,11 +1258,14 @@ dotlock_take (dotlock_t h, long timeout) int ret; if ( h->disable ) - return 0; /* Locks are completely disabled. Return success. */ + { + h->locked = 1; + return 0; /* Locks are completely disabled. Return success. */ + } if ( h->locked ) { - my_debug_1 ("Oops, '%s' is already locked\n", h->lockname); + /* my_debug_1 ("'%s' is already locked (%s)\n", h->lockname); */ return 0; } @@ -1346,11 +1357,14 @@ dotlock_release (dotlock_t h) return 0; if ( h->disable ) - return 0; + { + h->locked = 0; + return 0; + } if ( !h->locked ) { - my_debug_1 ("Oops, '%s' is not locked\n", h->lockname); + /* my_debug_1 ("Oops, '%s' is not locked (%s)\n", h->lockname); */ return 0; } diff --git a/common/dotlock.h b/common/dotlock.h index 03131bb0c..98697394a 100644 --- a/common/dotlock.h +++ b/common/dotlock.h @@ -102,6 +102,7 @@ dotlock_t dotlock_create (const char *file_to_lock, unsigned int flags); void dotlock_set_fd (dotlock_t h, int fd); int dotlock_get_fd (dotlock_t h); void dotlock_destroy (dotlock_t h); +int dotlock_is_locked (dotlock_t h); int dotlock_take (dotlock_t h, long timeout); int dotlock_release (dotlock_t h); void dotlock_remove_lockfiles (void);