Skip to content

Commit 3dc105a

Browse files
jhelmoldbjoernricks
authored andcommitted
Fix: Optimized "gvmd --get-users" and "gvmd --get-roles" command.
Optimized the "gvmd --get-users" and the "gvmd --get-roles" command by skipping the update of the nvti cache in those cases. Also added a retry loop around "lockfile_lock_nb (...)" so that commands like "gvmd --get-users" don't fail if another gvmd process is starting up.
1 parent 1e5c9f5 commit 3dc105a

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

src/gvmd.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -2561,7 +2561,19 @@ gvmd (int argc, char** argv, char *env[])
25612561
* associated files are closed (i.e. when all processes exit). */
25622562

25632563

2564-
switch (lockfile_lock_nb (&lockfile_checking, "gvm-checking"))
2564+
int lock_ret;
2565+
int retries = 0;
2566+
2567+
lock_ret = lockfile_lock_nb (&lockfile_checking, "gvm-checking");
2568+
2569+
while (lock_ret == 1 && retries < MAX_LOCK_RETRIES)
2570+
{
2571+
gvm_sleep (4);
2572+
lock_ret = lockfile_lock_nb (&lockfile_checking, "gvm-checking");
2573+
retries++;
2574+
}
2575+
2576+
switch (lock_ret)
25652577
{
25662578
case 0:
25672579
break;
@@ -2991,7 +3003,9 @@ gvmd (int argc, char** argv, char *env[])
29913003
if (option_lock (&lockfile_checking))
29923004
return EXIT_FAILURE;
29933005

3006+
set_skip_update_nvti_cache (TRUE);
29943007
ret = manage_get_roles (log_config, &database, verbose);
3008+
set_skip_update_nvti_cache (FALSE);
29953009
log_config_free ();
29963010
if (ret)
29973011
return EXIT_FAILURE;
@@ -3007,7 +3021,9 @@ gvmd (int argc, char** argv, char *env[])
30073021
if (option_lock (&lockfile_checking))
30083022
return EXIT_FAILURE;
30093023

3024+
set_skip_update_nvti_cache (TRUE);
30103025
ret = manage_get_users (log_config, &database, role, verbose);
3026+
set_skip_update_nvti_cache (FALSE);
30113027
log_config_free ();
30123028
if (ret)
30133029
return EXIT_FAILURE;

src/manage.h

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ manage_reset_currents ();
144144

145145
/* Commands. */
146146

147+
#define MAX_LOCK_RETRIES 16
148+
147149
/**
148150
* @brief A command.
149151
*/

src/manage_sql.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -17275,11 +17275,14 @@ init_manage_internal (GSList *log_config,
1727517275

1727617276
/* Load the NVT cache into memory. */
1727717277

17278-
if (nvti_cache == NULL)
17278+
if (nvti_cache == NULL && !skip_update_nvti_cache ())
1727917279
update_nvti_cache ();
1728017280

17281+
if (skip_update_nvti_cache ())
17282+
avoid_db_check_inserts = TRUE;
17283+
1728117284
if (skip_db_check == 0)
17282-
/* Requires NVT cache. */
17285+
/* Requires NVT cache if avoid_db_check_inserts == FALSE */
1728317286
check_db_configs (avoid_db_check_inserts);
1728417287

1728517288
sql_close ();

src/utils.c

+27
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
*/
5959
#define G_LOG_DOMAIN "md manage"
6060

61+
/* Flag if to skip the update of the nvti cache or not. */
62+
static gboolean skip_upd_nvti_cache = FALSE;
63+
6164

6265
/* Sleep. */
6366

@@ -753,6 +756,30 @@ lockfile_locked (const gchar *lockfile_basename)
753756
return ret;
754757
}
755758

759+
/**
760+
* @brief Set Flag if to run update_nvti_cache () or not.
761+
* The default value of the flag is FALSE.
762+
*
763+
* @param[in] skip_upd_nvti_c Value for the flag if to
764+
* skip the cache update or not.
765+
*/
766+
void
767+
set_skip_update_nvti_cache (gboolean skip_upd_nvti_c)
768+
{
769+
skip_upd_nvti_cache = skip_upd_nvti_c;
770+
}
771+
772+
/**
773+
* @brief Check if to run update_nvti_cache () or not.
774+
*
775+
* @return TRUE skip update, FALSE don't skip update
776+
*/
777+
gboolean
778+
skip_update_nvti_cache ()
779+
{
780+
return skip_upd_nvti_cache;
781+
}
782+
756783

757784
/* UUIDs. */
758785

src/utils.h

+6
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ lockfile_unlock (lockfile_t *);
8585
int
8686
lockfile_locked (const gchar *);
8787

88+
void
89+
set_skip_update_nvti_cache (gboolean);
90+
91+
gboolean
92+
skip_update_nvti_cache ();
93+
8894
int
8995
is_uuid (const char *);
9096

0 commit comments

Comments
 (0)