summaryrefslogtreecommitdiff
path: root/src/posix-lock.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2019-01-04 13:13:53 +0100
committerWerner Koch <wk@gnupg.org>2019-01-04 13:13:53 +0100
commit933bfd7b652a907c0d8dd5337c6b5b9cb82ce7b7 (patch)
tree2c3d78726642c6ccad34296082d5c85e3189a51c /src/posix-lock.c
parent12349de46d241cfbadbdf99773d6cabfcbc97578 (diff)
downloadlibgpg-error-933bfd7b652a907c0d8dd5337c6b5b9cb82ce7b7.tar.gz
core: New functions gpgrt_abort and gpgrt_add_emergency_cleanup.
* src/init.c (emergency_cleanup_list): New gloabl var. (_gpgrt_add_emergency_cleanup): New. (_gpgrt_abort): New. Repalce all calls to abort by this. Also replace all assert by either log_assert or a stderr output followed by a _gpgrt_abort. (run_emergency_cleanup): New. * src/visibility.c (gpgrt_add_emergency_cleanup): New public API. (gpgrt_abort): New public API. -- Libgcrypt uses its own assert function which makes sure to terminate the secure memory. This is safe as log as an assert is triggered internally in Libgcrypt. GnuPG runs emergency cleanup handlers right before log_fatal etc to tell Libgcrypt to terminate the secure memory. With the move of the logging function to gpgrt in gnupg 2.3 this did not anymore. Thus we now provide a mechanism in gpgrt to do right that. Eventually Libgcrypt can also make use of this. What this does not handle are calls to abort or failed asserts in external libraries or in libc. We can't do anything about it in a library because a library may not setup signal handlers. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src/posix-lock.c')
-rw-r--r--src/posix-lock.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/posix-lock.c b/src/posix-lock.c
index b5e6916..be4cc27 100644
--- a/src/posix-lock.c
+++ b/src/posix-lock.c
@@ -33,7 +33,6 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
-#include <assert.h>
#if USE_POSIX_THREADS
# include <pthread.h>
@@ -90,8 +89,9 @@ use_pthread_p (void)
void *retval;
if (pthread_join (thread, &retval) != 0)
{
- assert (!"pthread_join");
- abort ();
+ fputs ("gpgrt fatal: pthread_join in use_pthread_p failed\n",
+ stderr);
+ _gpgrt_abort ();
}
result = 1;
}
@@ -110,13 +110,13 @@ get_lock_object (gpgrt_lock_t *lockhd)
if (lock->vers != LOCK_ABI_VERSION)
{
- assert (!"lock ABI version");
- abort ();
+ fputs ("gpgrt fatal: lock ABI version mismatch\n", stderr);
+ _gpgrt_abort ();
}
if (sizeof (gpgrt_lock_t) < sizeof (_gpgrt_lock_t))
{
- assert (!"sizeof lock obj");
- abort ();
+ fputs ("gpgrt fatal: sizeof lock obj\n", stderr);
+ _gpgrt_abort ();
}
return lock;
@@ -136,8 +136,8 @@ _gpgrt_lock_init (gpgrt_lock_t *lockhd)
{
if (sizeof (gpgrt_lock_t) < sizeof (_gpgrt_lock_t))
{
- assert (!"sizeof lock obj");
- abort ();
+ fputs ("gpgrt fatal: sizeof lock obj\n", stderr);
+ _gpgrt_abort ();
}
lock->vers = LOCK_ABI_VERSION;
}