diff options
author | Werner Koch <[email protected]> | 2019-05-14 11:36:08 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2019-05-14 11:36:08 +0000 |
commit | 22e274f839f9a6c9a511648f29cae497f6492c97 (patch) | |
tree | c1919fa1f95a1a95f23079271ffc2480c115a546 /kbx/keybox-init.c | |
parent | agent: Replace most assert by log_assert. (diff) | |
download | gnupg-22e274f839f9a6c9a511648f29cae497f6492c97.tar.gz gnupg-22e274f839f9a6c9a511648f29cae497f6492c97.zip |
sm: Change keydb code to use the keybox locking.
* kbx/keybox-init.c (keybox_lock): New arg TIMEOUT. Change all
callers to pass -1 when locking.
* sm/keydb.c (struct resource_item): Remove LOCKANDLE.
(struct keydb_handle): Add KEEP_LOCK.
(keydb_add_resource): Use keybox locking instead of a separate dotlock
for testing whether we can run a compress.
(keydb_release): Reset KEEP_LOCK.
(keydb_lock): Set KEEP_LOCK.
(unlock_all): Take care of KEEP_LOCK.
(lock_all): Use keybox_lock instead of dotlock fucntions.
(keydb_delete): Remove arg UNLOCK.
* sm/delete.c (delete_one): Adjust keydb_delete. Due to the KEEP_LOCK
the keydb_release takes care of unlocking.
--
This aligns the code more with g10/keydb.c and avoids the separate
calls to dotlock_take.
GnuPG-bug-id: 4505
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'kbx/keybox-init.c')
-rw-r--r-- | kbx/keybox-init.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/kbx/keybox-init.c b/kbx/keybox-init.c index 6a83f7162..9a65c1345 100644 --- a/kbx/keybox-init.c +++ b/kbx/keybox-init.c @@ -261,10 +261,12 @@ _keybox_close_file (KEYBOX_HANDLE hd) /* - * Lock the keybox at handle HD, or unlock if YES is false. + * Lock the keybox at handle HD, or unlock if YES is false. TIMEOUT + * is the value used for dotlock_take. In general -1 should be used + * when taking a lock; use 0 when releasing a lock. */ gpg_error_t -keybox_lock (KEYBOX_HANDLE hd, int yes) +keybox_lock (KEYBOX_HANDLE hd, int yes, long timeout) { gpg_error_t err = 0; KB_NAME kb = hd->kb; @@ -302,10 +304,13 @@ keybox_lock (KEYBOX_HANDLE hd, int yes) hd->fp = NULL; } #endif /*HAVE_W32_SYSTEM*/ - if (dotlock_take (kb->lockhd, -1)) + if (dotlock_take (kb->lockhd, timeout)) { err = gpg_error_from_syserror (); - log_info ("can't lock '%s'\n", kb->fname ); + if (!timeout && gpg_err_code (err) == GPG_ERR_EACCES) + ; /* No diagnostic if we only tried to lock. */ + else + log_info ("can't lock '%s'\n", kb->fname ); } else kb->is_locked = 1; |