mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-31 11:41:32 +01:00
Add dotlock_get_fd and dotlock_set_fd.
This commit is contained in:
parent
bf3d5beb71
commit
f61b5371c4
@ -4,6 +4,7 @@
|
||||
[DOTLOCK_USE_PTHREAD] (all_lockfiles_mutex): New.
|
||||
(LOCK_all_lockfiles, UNLOCK_all_lockfiles): New. Use them to
|
||||
protect access to all_lockfiles.
|
||||
(dotlock_set_fd, dotlock_get_fd): New.
|
||||
|
||||
2011-09-28 Werner Koch <wk@g10code.com>
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
@ -788,6 +802,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. */
|
||||
|
@ -27,6 +27,8 @@ typedef struct dotlock_handle *dotlock_t;
|
||||
|
||||
void dotlock_disable (void);
|
||||
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_take (dotlock_t h, long timeout);
|
||||
int dotlock_release (dotlock_t h);
|
||||
|
Loading…
x
Reference in New Issue
Block a user