From fed1c0a3caab37720b6617975e7ae88ba191d9e7 Mon Sep 17 00:00:00 2001 From: hkc Date: Sat, 18 Nov 2023 14:14:01 +0300 Subject: [PATCH] Error checking on pthread_create --- .gitignore | 2 +- cbt.h | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index a482009..3dede65 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ cbt cbt_impl.c state -add_impl.py +add-impl.py diff --git a/cbt.h b/cbt.h index 31e91da..1604d49 100644 --- a/cbt.h +++ b/cbt.h @@ -147,7 +147,6 @@ const char *cbt_log__colors[CBT_LOG_ALL + 1] = { const char *cbt_log__text[CBT_LOG_ALL + 1] = {"FATAL", "ERROR", "WARN ", "INFO ", "DEBUG", "TRACE"}; - void *cbt__line_processor(void *); void cbt__init(int argc, char **argv, const char *source_file) { @@ -155,8 +154,7 @@ void cbt__init(int argc, char **argv, const char *source_file) { cbt_running = true; (void)argc; - cbt_log(CBT_LOG_INFO, "Running CBT build %s %s from %s", __DATE__, __TIME__, - __FILE__); + cbt_log(CBT_LOG_INFO, "Running CBT build %s %s from %s", __DATE__, __TIME__, __FILE__); if (!cbt_cc) cbt_cc = getenv("CC"); @@ -171,8 +169,12 @@ void cbt__init(int argc, char **argv, const char *source_file) { calloc(cbt__default_procgroup.cap, sizeof(struct cbt_proc)); cbt_log(CBT_LOG_DEBUG, "Starting line processor thread"); - // TODO: error checking - pthread_create(&_cbt__autoproc_thread, NULL, cbt__line_processor, NULL); + + int err; + if ((err = pthread_create(&_cbt__autoproc_thread, NULL, cbt__line_processor, NULL)) != 0) { + cbt_log(CBT_LOG_ERROR, "pthread_create() failed for line processor: %d", err); + exit(1); + } if (cbt_needs_recompilation(source_file, argv[0])) { cbt_log(CBT_LOG_INFO, "Recompiling...");