aboutsummaryrefslogtreecommitdiffstats
path: root/kbx/keybox-init.c
diff options
context:
space:
mode:
Diffstat (limited to 'kbx/keybox-init.c')
-rw-r--r--kbx/keybox-init.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/kbx/keybox-init.c b/kbx/keybox-init.c
index 6a83f7162..2223f4d15 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;
@@ -289,23 +291,22 @@ keybox_lock (KEYBOX_HANDLE hd, int yes)
if (!kb->is_locked)
{
#ifdef HAVE_W32_SYSTEM
- /* Under Windows we need to close the file before we try
- * to lock it. This is because another process might have
- * taken the lock and is using keybox_file_rename to
- * rename the base file. How if our dotlock_take below is
- * waiting for the lock but we have the base file still
- * open, keybox_file_rename will never succeed as we are
- * in a deadlock. */
- if (hd->fp)
- {
- fclose (hd->fp);
- hd->fp = NULL;
- }
+ /* Under Windows we need to close the file before we try
+ * to lock it. This is because another process might have
+ * taken the lock and is using keybox_file_rename to
+ * rename the base file. Now if our dotlock_take below is
+ * waiting for the lock but we have the base file still
+ * open, keybox_file_rename will never succeed as we are
+ * in a deadlock. */
+ _keybox_close_file (hd);
#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;