Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Optimized "gvmd --get-users" and "gvmd --get-roles" command. #2337

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ manage_reset_currents ();

/* Commands. */

#define MAX_LOCK_RETRIES 16

/**
* @brief A command.
*/
Expand Down
7 changes: 5 additions & 2 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -17264,11 +17264,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 ();
Expand Down
27 changes: 27 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */

Expand Down Expand Up @@ -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. */

Expand Down
5 changes: 5 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);

Expand Down
Loading