From 894598e89d53d299ef6711f5fb21cef4c8b445dd Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 4 Aug 2019 18:50:38 +0200 Subject: [PATCH] make sure we initilize the database mutex at the beginning of db_init() to ensure we always have the lock available. Signed-off-by: DL6ER --- src/database/common.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/database/common.c b/src/database/common.c index effada5f..66fb9438 100644 --- a/src/database/common.c +++ b/src/database/common.c @@ -221,6 +221,14 @@ void db_init(void) return; } + // Initialize database lock mutex + if (pthread_mutex_init(&dblock, NULL) != 0) + { + logg("FATAL: FTL_db mutex init failed\n"); + // Return failure + exit(EXIT_FAILURE); + } + // Initialize SQLite3 logging callback // This ensures SQLite3 errors and warnings are logged to pihole-FTL.log // We use this to possibly catch even more errors in places we do not @@ -322,13 +330,6 @@ void db_init(void) // we already closed the database when we returned earlier sqlite3_close(FTL_db); - if (pthread_mutex_init(&dblock, NULL) != 0) - { - logg("FATAL: FTL_db mutex init failed\n"); - // Return failure - exit(EXIT_FAILURE); - } - logg("Database successfully initialized"); }