1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

kbx: Improve and fix keybox_lock.

* kbx/keybox-init.c (keybox_lock): Make sure ERR is initialized.  Get
error codes from dotlock functions.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2016-01-13 14:47:06 +01:00
parent 4aceebf36f
commit 8f1368d5e3
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -266,10 +266,10 @@ _keybox_close_file (KEYBOX_HANDLE hd)
gpg_error_t gpg_error_t
keybox_lock (KEYBOX_HANDLE hd, int yes) keybox_lock (KEYBOX_HANDLE hd, int yes)
{ {
gpg_error_t err; gpg_error_t err = 0;
KB_NAME kb = hd->kb; KB_NAME kb = hd->kb;
if (!keybox_is_writable ((void*)kb)) if (!keybox_is_writable (kb))
return 0; return 0;
/* Make sure the lock handle has been created. */ /* Make sure the lock handle has been created. */
@ -278,9 +278,9 @@ keybox_lock (KEYBOX_HANDLE hd, int yes)
kb->lockhd = dotlock_create (kb->fname, 0); kb->lockhd = dotlock_create (kb->fname, 0);
if (!kb->lockhd) if (!kb->lockhd)
{ {
/* Unfortuntaley dotlock_create does not properly set ERRNO. */ err = gpg_error_from_syserror ();
log_info ("can't allocate lock for '%s'\n", kb->fname ); log_info ("can't allocate lock for '%s'\n", kb->fname );
return gpg_error (GPG_ERR_GENERAL); return err;
} }
} }
@ -288,28 +288,26 @@ keybox_lock (KEYBOX_HANDLE hd, int yes)
{ {
if (kb->is_locked) if (kb->is_locked)
; ;
else if (!dotlock_take (kb->lockhd, -1)) else if (dotlock_take (kb->lockhd, -1))
kb->is_locked = 1;
else
{ {
/* Unfortuntaley dotlock_take does not properly set ERRNO. */ err = gpg_error_from_syserror ();
log_info ("can't lock '%s'\n", kb->fname ); log_info ("can't lock '%s'\n", kb->fname );
err = gpg_error (GPG_ERR_GENERAL);
} }
else
kb->is_locked = 1;
} }
else /* Release the lock. */ else /* Release the lock. */
{ {
if (!kb->is_locked) if (!kb->is_locked)
; ;
else if (!dotlock_release (kb->lockhd)) else if (dotlock_release (kb->lockhd))
kb->is_locked = 0;
else
{ {
/* Unfortuntaley dotlock_release does not properly set ERRNO. */ err = gpg_error_from_syserror ();
log_info ("can't unlock '%s'\n", kb->fname ); log_info ("can't unlock '%s'\n", kb->fname );
err = gpg_error (GPG_ERR_GENERAL);
} }
} else
kb->is_locked = 0;
}
return err; return err;
} }