Skip to content

Commit 22e591e

Browse files
committed
Add --secinfo-fast_init option to toggle COPY SQL
1 parent 5162a75 commit 22e591e

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

doc/gvmd.8

+3
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ Time out tasks that are more than TIME minutes overdue. -1 to disable, 0 for min
217217
\fB--secinfo-commit-size=\fINUMBER\fB\f1
218218
During CERT and SCAP sync, commit updates to the database every NUMBER items, 0 for unlimited.
219219
.TP
220+
\fB--secinfo-fast_init=\fINUMBER\fB\f1
221+
Whether to prefer faster SQL with less checks for non-incremental SecInfo updates. 0 to use statements with more checks, 1 to use faster statements, default: 1
222+
.TP
220223
\fB-c, --unix-socket=\fIFILENAME\fB\f1
221224
Listen on UNIX socket at FILENAME.
222225
.TP

doc/gvmd.8.xml

+8
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
508508
NUMBER items, 0 for unlimited.</p>
509509
</optdesc>
510510
</option>
511+
<option>
512+
<p><opt>--secinfo-fast_init=<arg>NUMBER</arg></opt></p>
513+
<optdesc>
514+
<p>Whether to prefer faster SQL with less checks for non-incremental
515+
SecInfo updates. 0 to use statements with more checks, 1 to use
516+
faster statements, default: 1</p>
517+
</optdesc>
518+
</option>
511519
<option>
512520
<p><opt>-c, --unix-socket=<arg>FILENAME</arg></opt></p>
513521
<optdesc>

doc/gvmd.html

+8
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,14 @@ <h2>Options</h2>
451451

452452

453453

454+
<p><b>--secinfo-fast-init=<em>NUMBER</em></b></p>
455+
456+
<p>Whether to prefer faster SQL with less checks for non-incremental
457+
SecInfo updates. 0 to use statements with more checks, 1 to use
458+
faster statements, default: 1</p>
459+
460+
461+
454462
<p><b>--slave-commit-size=<em>NUMBER</em></b></p>
455463

456464
<p>During slave updates, commit after every NUMBER updated results and

src/gvmd.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,7 @@ gvmd (int argc, char** argv, char *env[])
18671867
static int schedule_timeout = SCHEDULE_TIMEOUT_DEFAULT;
18681868
static int affected_products_query_size
18691869
= AFFECTED_PRODUCTS_QUERY_SIZE_DEFAULT;
1870+
static int secinfo_fast_init = SECINFO_FAST_INIT_DEFAULT;
18701871
static int secinfo_commit_size = SECINFO_COMMIT_SIZE_DEFAULT;
18711872
static gchar *delete_scanner = NULL;
18721873
static gchar *verify_scanner = NULL;
@@ -2242,6 +2243,13 @@ gvmd (int argc, char** argv, char *env[])
22422243
"During CERT and SCAP sync, commit updates to the database every"
22432244
" <number> items, 0 for unlimited, default: "
22442245
G_STRINGIFY (SECINFO_COMMIT_SIZE_DEFAULT), "<number>" },
2246+
{ "secinfo-fast-init", '\0', 0, G_OPTION_ARG_INT,
2247+
&secinfo_fast_init,
2248+
"Whether to prefer faster SQL with less checks for non-incremental"
2249+
" SecInfo updates."
2250+
" 0 to use statements with more checks, 1 to use faster statements,"
2251+
" default: "
2252+
G_STRINGIFY (SECINFO_FAST_INIT_DEFAULT), "<number>" },
22452253
{ "set-encryption-key", '\0', 0, G_OPTION_ARG_STRING,
22462254
&set_encryption_key,
22472255
"Set the encryption key with the given UID as the new default"
@@ -2370,7 +2378,9 @@ gvmd (int argc, char** argv, char *env[])
23702378
/* Set the connection auto retry */
23712379
set_scanner_connection_retry (scanner_connection_retry);
23722380

2373-
/* Set SQL sizes */
2381+
/* Set SQL sizes and related options */
2382+
2383+
set_secinfo_fast_init (secinfo_fast_init);
23742384

23752385
set_affected_products_query_size (affected_products_query_size);
23762386

src/manage_sql_secinfo.c

+22-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ static int affected_products_query_size = AFFECTED_PRODUCTS_QUERY_SIZE_DEFAULT;
8181
*/
8282
static int secinfo_commit_size = SECINFO_COMMIT_SIZE_DEFAULT;
8383

84+
/**
85+
* @brief Whether to prefer faster SQL with less checks for non-incremental
86+
* SecInfo updates.
87+
*/
88+
static int secinfo_fast_init = SECINFO_FAST_INIT_DEFAULT;
89+
8490
/**
8591
* @brief Maximum number of rows in a EPSS INSERT.
8692
*/
@@ -3199,7 +3205,7 @@ update_scap_cpes ()
31993205

32003206
g_info ("Updating CPEs");
32013207

3202-
ret = update_scap_cpes_from_json_file (full_path, TRUE);
3208+
ret = update_scap_cpes_from_json_file (full_path, secinfo_fast_init);
32033209

32043210
g_free (full_path);
32053211

@@ -4638,7 +4644,7 @@ update_scap_cpe_match_strings ()
46384644
gvm_json_pull_parser_t parser;
46394645
inserts_t inserts, matches_inserts;
46404646
db_copy_buffer_t copy_buffer, matches_copy_buffer;
4641-
gboolean use_copy = TRUE;
4647+
gboolean use_copy = secinfo_fast_init;
46424648

46434649
current_json_path = g_build_filename (GVM_SCAP_DATA_DIR,
46444650
"nvd-cpe-matches.json.gz",
@@ -6270,3 +6276,17 @@ set_secinfo_commit_size (int new_commit_size)
62706276
else
62716277
secinfo_commit_size = new_commit_size;
62726278
}
6279+
6280+
/**
6281+
* @brief Set the SecInfo fast initialization option.
6282+
*
6283+
* @param new_fast_init The new SecInfo fast initialization option.
6284+
*/
6285+
void
6286+
set_secinfo_fast_init (int new_fast_init)
6287+
{
6288+
if (new_fast_init < 0)
6289+
secinfo_fast_init = SECINFO_FAST_INIT_DEFAULT;
6290+
else
6291+
secinfo_fast_init = new_fast_init;
6292+
}

src/manage_sql_secinfo.h

+8
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
*/
171171
#define AFFECTED_PRODUCTS_QUERY_SIZE_DEFAULT 1000
172172

173+
/**
174+
* @brief Default for secinfo_copy.
175+
*/
176+
#define SECINFO_FAST_INIT_DEFAULT 1
177+
173178
/**
174179
* @brief Default for secinfo_commit_size.
175180
*/
@@ -202,6 +207,9 @@ set_affected_products_query_size (int);
202207
void
203208
set_secinfo_commit_size (int);
204209

210+
void
211+
set_secinfo_fast_init (int);
212+
205213
void
206214
update_scap_extra ();
207215

0 commit comments

Comments
 (0)