diff options
author | Werner Koch <[email protected]> | 2023-12-13 09:08:12 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2023-12-18 14:21:26 +0000 |
commit | 937aeb1904eb5cbe7a8c1c686877c7a9e1196ca6 (patch) | |
tree | dc8e4dbd870fff29ceb2248d61d19769a81338af /common/dotlock.h | |
parent | common: Improve error return for dotlock. (diff) | |
download | gnupg-937aeb1904eb5cbe7a8c1c686877c7a9e1196ca6.tar.gz gnupg-937aeb1904eb5cbe7a8c1c686877c7a9e1196ca6.zip |
common: Add an info callback to dotlock.
* common/dotlock.h (enum dotlock_reasons): New.
(DOTLOCK_PREPARE_CREATE): New flag.
* common/dotlock.c (struct dotlock_handle): Add info_cb and
info_cb_value.
(dotlock_create): Support the new flag.
(dotlock_finish_create): New.
(read_lockfile): Silence in case of ENOENT.
(dotlock_set_info_cb): New. Use callback after all error and info
messages.
(dotlock_take_unix, dotlock_take_w32): Allow termination by callback.
Diffstat (limited to 'common/dotlock.h')
-rw-r--r-- | common/dotlock.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/common/dotlock.h b/common/dotlock.h index 03131bb0c..915279176 100644 --- a/common/dotlock.h +++ b/common/dotlock.h @@ -97,12 +97,32 @@ extern "C" struct dotlock_handle; typedef struct dotlock_handle *dotlock_t; +enum dotlock_reasons + { + DOTLOCK_CONFIG_TEST, /* Can't check system - function terminates. */ + DOTLOCK_FILE_ERROR, /* General file error - function terminates. */ + DOTLOCK_INV_FILE, /* Invalid file - function terminates. */ + DOTLOCK_CONFLICT, /* Something is wrong - function terminates. */ + DOTLOCK_NOT_LOCKED, /* Not locked - No action required. */ + DOTLOCK_STALE_REMOVED, /* Stale lock file was removed - retrying. */ + DOTLOCK_WAITING /* Waiting for the lock - may be terminated. */ + }; + +#define DOTLOCK_PREPARE_CREATE (1<<5) /* Require dotlock_finish_create. */ + void dotlock_disable (void); dotlock_t dotlock_create (const char *file_to_lock, unsigned int flags); +dotlock_t dotlock_finish_create (dotlock_t h, const char *file_to_lock); void dotlock_set_fd (dotlock_t h, int fd); int dotlock_get_fd (dotlock_t h); +void dotlock_set_info_cb (dotlock_t h, + int (*cb)(dotlock_t, void *, + enum dotlock_reasons reason, + const char *,...), + void *opaque); void dotlock_destroy (dotlock_t h); int dotlock_take (dotlock_t h, long timeout); +int dotlock_is_locked (dotlock_t h); int dotlock_release (dotlock_t h); void dotlock_remove_lockfiles (void); |