common: New function dotlock_is_locked.

* common/dotlock.c (dotlock_is_locked): New.
(dotlock_take): Set locked flag also in disabled mode.  No more
warning if the lock has already been taken.
(dotlock_release): Clear locked flag also in disabled mode.  No more
warning if the lock has not been taken.
--

This allow to use dotlock_take and dotlock_release even if they have
already been called.  Before this changes this worked too but a
diagnostic was printed.
This commit is contained in:
Werner Koch 2021-03-02 18:34:01 +01:00
parent 677245ba0e
commit 67b82a9c60
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 19 additions and 4 deletions

View File

@ -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;
}

View File

@ -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);