diff --git a/src/gvmd.c b/src/gvmd.c index f5c0100b0..3a2a3a6aa 100644 --- a/src/gvmd.c +++ b/src/gvmd.c @@ -2561,7 +2561,19 @@ gvmd (int argc, char** argv, char *env[]) * associated files are closed (i.e. when all processes exit). */ - switch (lockfile_lock_nb (&lockfile_checking, "gvm-checking")) + int lock_ret; + int retries = 0; + + lock_ret = lockfile_lock_nb (&lockfile_checking, "gvm-checking"); + + while (lock_ret == 1 && retries < MAX_LOCK_RETRIES) + { + gvm_sleep (4); + lock_ret = lockfile_lock_nb (&lockfile_checking, "gvm-checking"); + retries++; + } + + switch (lock_ret) { case 0: break; @@ -2991,7 +3003,9 @@ gvmd (int argc, char** argv, char *env[]) if (option_lock (&lockfile_checking)) return EXIT_FAILURE; + set_skip_update_nvti_cache (TRUE); ret = manage_get_roles (log_config, &database, verbose); + set_skip_update_nvti_cache (FALSE); log_config_free (); if (ret) return EXIT_FAILURE; @@ -3007,7 +3021,9 @@ gvmd (int argc, char** argv, char *env[]) if (option_lock (&lockfile_checking)) return EXIT_FAILURE; + set_skip_update_nvti_cache (TRUE); ret = manage_get_users (log_config, &database, role, verbose); + set_skip_update_nvti_cache (FALSE); log_config_free (); if (ret) return EXIT_FAILURE; diff --git a/src/manage.h b/src/manage.h index ce073b277..3d8dfa9d1 100644 --- a/src/manage.h +++ b/src/manage.h @@ -144,6 +144,8 @@ manage_reset_currents (); /* Commands. */ +#define MAX_LOCK_RETRIES 16 + /** * @brief A command. */ diff --git a/src/manage_sql.c b/src/manage_sql.c index 99635d030..7d26fa904 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -17275,11 +17275,14 @@ init_manage_internal (GSList *log_config, /* Load the NVT cache into memory. */ - if (nvti_cache == NULL) + if (nvti_cache == NULL && !skip_update_nvti_cache ()) update_nvti_cache (); + if (skip_update_nvti_cache ()) + avoid_db_check_inserts = TRUE; + if (skip_db_check == 0) - /* Requires NVT cache. */ + /* Requires NVT cache if avoid_db_check_inserts == FALSE */ check_db_configs (avoid_db_check_inserts); sql_close (); diff --git a/src/utils.c b/src/utils.c index 32588497b..115a3efc1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -58,6 +58,9 @@ */ #define G_LOG_DOMAIN "md manage" +/* Flag if to skip the update of the nvti cache or not. */ +static gboolean skip_upd_nvti_cache = FALSE; + /* Sleep. */ @@ -753,6 +756,30 @@ lockfile_locked (const gchar *lockfile_basename) return ret; } +/** + * @brief Set Flag if to run update_nvti_cache () or not. + * The default value of the flag is FALSE. + * + * @param[in] skip_upd_nvti_c Value for the flag if to + * skip the cache update or not. + */ +void +set_skip_update_nvti_cache (gboolean skip_upd_nvti_c) +{ + skip_upd_nvti_cache = skip_upd_nvti_c; +} + +/** + * @brief Check if to run update_nvti_cache () or not. + * + * @return TRUE skip update, FALSE don't skip update + */ +gboolean +skip_update_nvti_cache () +{ + return skip_upd_nvti_cache; +} + /* UUIDs. */ diff --git a/src/utils.h b/src/utils.h index 10fcf59d8..ed97ff74f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -85,6 +85,11 @@ lockfile_unlock (lockfile_t *); int lockfile_locked (const gchar *); +void set_skip_update_nvti_cache (gboolean); + +gboolean +skip_update_nvti_cache (); + int is_uuid (const char *);