diff options
author | Werner Koch <[email protected]> | 2016-08-03 13:31:27 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2016-08-03 13:31:27 +0000 |
commit | 48a2c93a1886589d1a0e2a4a2173e0e81311200b (patch) | |
tree | 80cee1c6eb19941ab9676482f9eb4984d7360e83 /kbx/keybox-util.c | |
parent | common: New file utilproto.c (diff) | |
download | gnupg-48a2c93a1886589d1a0e2a4a2173e0e81311200b.tar.gz gnupg-48a2c93a1886589d1a0e2a4a2173e0e81311200b.zip |
gpg,gpgsm: Block signals during keyring/keybox update.
* kbx/keybox-util.c (keybox_file_rename): Add arg BLOCK_SIGNALS.
* kbx/keybox-update.c (rename_tmp_file): Block all signals when doing
a double rename.
* g10/keyring.c (rename_tmp_file): Block all signals during the double
rename.
--
This might fix
Debian-bug-id: 831510
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'kbx/keybox-util.c')
-rw-r--r-- | kbx/keybox-util.c | 92 |
1 files changed, 54 insertions, 38 deletions
diff --git a/kbx/keybox-util.c b/kbx/keybox-util.c index 13fedb32f..a2ca3f0ed 100644 --- a/kbx/keybox-util.c +++ b/kbx/keybox-util.c @@ -27,6 +27,7 @@ #endif #include "keybox-defs.h" +#include "utilproto.h" static void *(*alloc_func)(size_t n) = malloc; @@ -147,55 +148,70 @@ keybox_tmp_names (const char *filename, int for_keyring, } -/* Wrapper for rename(2) to handle Windows peculiarities. */ +/* Wrapper for rename(2) to handle Windows peculiarities. If + * BLOCK_SIGNALS is not NULL and points to a variable set to true, all + * signals will be blocked by calling gnupg_block_all_signals; the + * caller needs to call gnupg_unblock_all_signals if that variable is + * still set to true on return. */ gpg_error_t -keybox_file_rename (const char *oldname, const char *newname) +keybox_file_rename (const char *oldname, const char *newname, + int *block_signals) { gpg_error_t err = 0; -#ifdef HAVE_DOSISH_SYSTEM - int wtime = 0; + if (block_signals && *block_signals) + gnupg_block_all_signals (); - gnupg_remove (newname); - again: - if (rename (oldname, newname)) - { - if (GetLastError () == ERROR_SHARING_VIOLATION) - { - /* Another process has the file open. We do not use a lock - * for read but instead we wait until the other process has - * closed the file. This may take long but that would also - * be the case with a dotlock approach for read and write. - * Note that we don't need this on Unix due to the inode - * concept. - * - * So let's wait until the rename has worked. The retry - * intervals are 50, 100, 200, 400, 800, 50ms, ... */ - if (!wtime || wtime >= 800) - wtime = 50; - else - wtime *= 2; - - if (wtime >= 800) - log_info ("waiting for file '%s' to become accessible ...\n", - oldname); - - Sleep (wtime); - goto again; - } - err = gpg_error_from_syserror (); - } +#ifdef HAVE_DOSISH_SYSTEM + { + int wtime = 0; + gnupg_remove (newname); + again: + if (rename (oldname, newname)) + { + if (GetLastError () == ERROR_SHARING_VIOLATION) + { + /* Another process has the file open. We do not use a + * lock for read but instead we wait until the other + * process has closed the file. This may take long but + * that would also be the case with a dotlock approach for + * read and write. Note that we don't need this on Unix + * due to the inode concept. + * + * So let's wait until the rename has worked. The retry + * intervals are 50, 100, 200, 400, 800, 50ms, ... */ + if (!wtime || wtime >= 800) + wtime = 50; + else + wtime *= 2; + + if (wtime >= 800) + log_info ("waiting for file '%s' to become accessible ...\n", + oldname); + + Sleep (wtime); + goto again; + } + err = gpg_error_from_syserror (); + } + } #else /* Unix */ - + { #ifdef __riscos__ - gnupg_remove (newname); + gnupg_remove (newname); #endif - if (rename (oldname, newname) ) - err = gpg_error_from_syserror (); - + if (rename (oldname, newname) ) + err = gpg_error_from_syserror (); + } #endif /* Unix */ + if (block_signals && *block_signals && err) + { + gnupg_unblock_all_signals (); + *block_signals = 0; + } + if (err) log_error ("renaming '%s' to '%s' failed: %s\n", oldname, newname, gpg_strerror (err)); |