aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2021-03-02 17:34:01 +0000
committerWerner Koch <[email protected]>2021-03-02 18:11:53 +0000
commit67b82a9c607e1488972a85a30015f48c68245af0 (patch)
tree725e51dfd6a1d32844ed1e616181a2d59a4ed708
parentsm: Lock kbx files also before a search. (diff)
downloadgnupg-67b82a9c607e1488972a85a30015f48c68245af0.tar.gz
gnupg-67b82a9c607e1488972a85a30015f48c68245af0.zip
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.
-rw-r--r--common/dotlock.c22
-rw-r--r--common/dotlock.h1
2 files changed, 19 insertions, 4 deletions
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);