gpg: Fix trustdb updates without lock held.
* g10/tdbio.c (is_locked): Turn into a counter. (take_write_lock, release_write_lock): Implement recursive locks.
On trustdb creation we have this call sequence:
init_trustdb -> takes lock tdbio_set_dbname create_version_record tdbio_write_record put_record_into_cache -> takes lock put_record_into_cache -> releases lock init_trustdb -> releases lock
The second take lock does noting but the first release lock has
already released the lock and the second release lock is a thus a NOP.
This is likely the cause for the corrupted trustdb as reported in
- GnuPG-bug-id: T3839
- Signed-off-by: Werner Koch <wk@gnupg.org>