From 1469d494d1a9b97cc079eef07ec81472aeeecdb4 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Mon, 7 Sep 2020 20:06:55 +0200 Subject: [PATCH 1/2] Skip DB check in helpers when main process is running The DB check runs create_tables. Helper processes (--get-users etc) can safely skip the check when the main process is running, because the main process has done the check. This avoids deadlock. --- src/manage_sql.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/manage_sql.c b/src/manage_sql.c index f9399c506..943a6c53a 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -16414,8 +16414,13 @@ init_manage_internal (GSList *log_config, if (skip_db_check == 0) { - /* This only happens for init_manage callers with skip_db_check set, so - * there is ultimately only one caller case, the main process. */ + /* This only happens for init_manage callers with skip_db_check set to 0 + * and init_manage_helper callers. So there are only 2 callers: + * + * 1 the main process + * 2 a helper processes (--create-user, --get-users, etc) when the + * main process is not running. */ + ret = check_db (check_encryption_key); if (ret) return ret; @@ -16517,7 +16522,13 @@ init_manage_helper (GSList *log_config, const gchar *database, 0, /* Default max_email_message_size */ 0, /* Stop active tasks. */ NULL, - 0, /* Skip DB check. */ + /* Skip DB check if main process is running, to + * avoid locking issues when creating tables. + * + * Safe because main process did the check. */ + lockfile_locked ("gvm-serving") + ? 1 /* Skip DB check. */ + : 0, /* Do DB check. */ 0); /* Dummy. */ } From a484ac4c88573f5a8db886b738c3ca65ddc1577d Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Mon, 7 Sep 2020 20:14:24 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index feb6dde17..aba13832d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix alternative options for radio type preferences when exporting a scan_config [#1278](http://github.com/greenbone/gvmd/pull/1278) - Replace deprecated sys_siglist with strsignal [#1280](https://github.com/greenbone/gvmd/pull/1280) - Copy instead of moving when migrating predefined report formats [#1286](https://github.com/greenbone/gvmd/pull/1286) +- Skip DB check in helpers when main process is running [#1291](https://github.com/greenbone/gvmd/pull/1291) ### Removed - Remove DROP from vulns creation [#1281](http://github.com/greenbone/gvmd/pull/1281)