From 803d0dc6b9600277a3226ed9180b7c0ef668ba34 Mon Sep 17 00:00:00 2001 From: Utz-Uwe Haus <uhaus@hpe.com> Date: Sun, 26 Apr 2020 13:43:30 +0000 Subject: [PATCH] fix too-early-loggin-use crash --- maestro/logging.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/maestro/logging.c b/maestro/logging.c index b99cb24a..8ed767b5 100644 --- a/maestro/logging.c +++ b/maestro/logging.c @@ -208,7 +208,8 @@ mstro__ensure_threadid(void) /* valgrind users: this will leak. Sorry :) (we could use C11 _Tread_local instead, but need to check all compilers we care about do it well) */ char *tmp = malloc(16+2); if(tmp==NULL) { - ERR("Failed to allocate thread-identifier\n"); + /* cannot use our logging infrastructure yet, so use stderr */ + fprintf(stderr, "Failed to allocate thread-identifier\n"); abort(); } @@ -238,9 +239,15 @@ mstro__ensure_threadid(void) int s = pthread_setspecific(g_thread_descriptor_key, tid); if(s!=0) { - ERR("Failed to set thread identifier: %d (%s)\n", - errno, strerror(errno)); - abort(); + /* cannot use our logging infrastructure yet, so use stderr */ + if(s==EINVAL) { + fprintf(stderr, "Failed to set thread identifier; likely mstro_init has not been called, proceeding with caution\n"); + tid=0; + } else { + fprintf(stderr, "Failed to set thread identifier: %d (%s) (errno %d = %s)\n", + s, strerror(s), errno, strerror(errno)); + abort(); + } } } return tid; -- GitLab