aboutsummaryrefslogtreecommitdiffstats
path: root/common/dotlock.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2011-09-29 14:51:48 +0000
committerWerner Koch <[email protected]>2011-09-29 14:51:48 +0000
commitf61b5371c492b0685c179090372f35329e8a2028 (patch)
treecbc93056956ca13511298c0f7e80a6a81c648b63 /common/dotlock.c
parentMake dotlock.c thread-safe on pthread systems. (diff)
downloadgnupg-f61b5371c492b0685c179090372f35329e8a2028.tar.gz
gnupg-f61b5371c492b0685c179090372f35329e8a2028.zip
Add dotlock_get_fd and dotlock_set_fd.
Diffstat (limited to 'common/dotlock.c')
-rw-r--r--common/dotlock.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/common/dotlock.c b/common/dotlock.c
index 146394412..c65f6f637 100644
--- a/common/dotlock.c
+++ b/common/dotlock.c
@@ -100,8 +100,10 @@
if (dotlock_release (h))
error ("error releasing lock: %s\n", strerror (errno));
- or, if the lock file is not anymore needed, you may call
- dotlock_destroy.
+ or, if the lock file is not anymore needed, you may just call
+ dotlock_destroy. However dotlock_release does some extra checks
+ before releasing the lock and prints diagnostics to help detecting
+ bugs.
If you want to explicitly destroy all lock files you may call
@@ -114,6 +116,15 @@
before any locks are created.
+ There are two convenience functions to store an integer (e.g. a
+ file descriptor) value with the handle:
+
+ void dotlock_set_fd (dotlock_t h, int fd);
+ int dotlock_get_fd (dotlock_t h);
+
+ If nothing has been stored dotlock_get_fd returns -1.
+
+
How to build:
=============
@@ -336,6 +347,8 @@ struct dotlock_handle
unsigned int disable:1; /* If true, locking is disabled. */
unsigned int use_o_excl:1; /* Use open (O_EXCL) for locking. */
+ int extra_fd; /* A place for the caller to store an FD. */
+
#ifdef HAVE_DOSISH_SYSTEM
HANDLE lockhd; /* The W32 handle of the lock file. */
#else /*!HAVE_DOSISH_SYSTEM */
@@ -769,6 +782,7 @@ dotlock_create (const char *file_to_lock, unsigned int flags)
h = jnlib_calloc (1, sizeof *h);
if (!h)
return NULL;
+ h->extra_fd = -1;
if (never_lock)
{
@@ -789,6 +803,24 @@ dotlock_create (const char *file_to_lock, unsigned int flags)
+/* Convenience function to store a file descriptor (or any any other
+ integer value) in the context of handle H. */
+void
+dotlock_set_fd (dotlock_t h, int fd)
+{
+ h->extra_fd = fd;
+}
+
+/* Convenience function to retrieve a file descriptor (or any any other
+ integer value) stored in the context of handle H. */
+int
+dotlock_get_fd (dotlock_t h)
+{
+ return h->extra_fd;
+}
+
+
+
#ifdef HAVE_POSIX_SYSTEM
/* Unix specific code of destroy_dotlock. */
static void