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

Handle QUEUED task status for queued scans #1113

Merged
merged 3 commits into from
Jun 3, 2020
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add --rebuild-scap option [#1051](https://github.com/greenbone/gvmd/pull/1051)
- Stop current scheduling of task when permission denied [#1058](https://github.com/greenbone/gvmd/pull/1058)
- Trim malloc heap after updating cache [#1085](https://github.com/greenbone/gvmd/pull/1085)
- Handle QUEUED osp scan status. [#1113](https://github.com/greenbone/gvmd/pull/1113)

### Changed
- Update SCAP and CERT feed info in sync scripts [#810](https://github.com/greenbone/gvmd/pull/810)
Expand Down
28 changes: 24 additions & 4 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,8 @@ run_status_name (task_status_t status)

case TASK_STATUS_RUNNING: return "Running";

case TASK_STATUS_QUEUED: return "Queued";

case TASK_STATUS_STOP_REQUESTED_GIVEUP:
case TASK_STATUS_STOP_REQUESTED:
case TASK_STATUS_STOP_WAITING:
Expand Down Expand Up @@ -1611,6 +1613,8 @@ run_status_name_internal (task_status_t status)

case TASK_STATUS_RUNNING: return "Running";

case TASK_STATUS_QUEUED: return "Queued";

case TASK_STATUS_STOP_REQUESTED_GIVEUP:
case TASK_STATUS_STOP_REQUESTED:
return "Stop Requested";
Expand Down Expand Up @@ -2922,6 +2926,7 @@ slave_setup (gvm_connection_t *connection, const char *name, task_t task,
case TASK_STATUS_NEW:
case TASK_STATUS_REQUESTED:
case TASK_STATUS_RUNNING:
case TASK_STATUS_QUEUED:
case TASK_STATUS_STOP_WAITING:
case TASK_STATUS_INTERRUPTED:
break;
Expand Down Expand Up @@ -3545,7 +3550,7 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
char *host, *ca_pub, *key_pub, *key_priv;
int rc, port;
scanner_t scanner;
gboolean started;
gboolean started, queued_status_updated;

scanner = task_scanner (task);
host = scanner_host (scanner);
Expand All @@ -3554,6 +3559,7 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
key_pub = scanner_key_pub (scanner);
key_priv = scanner_key_priv (scanner);
started = FALSE;
queued_status_updated = FALSE;

while (1)
{
Expand Down Expand Up @@ -3608,7 +3614,18 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)

osp_scan_status = get_osp_scan_status (scan_id, host, port,
ca_pub, key_pub, key_priv);
if (progress >= 0 && progress < 100

if (osp_scan_status == OSP_SCAN_STATUS_QUEUED)
{
if (queued_status_updated == FALSE)
{
set_task_run_status (task, TASK_STATUS_QUEUED);
set_report_scan_run_status (global_current_report,
TASK_STATUS_QUEUED);
queued_status_updated = TRUE;
}
}
else if (progress >= 0 && progress < 100
&& osp_scan_status == OSP_SCAN_STATUS_STOPPED)
{
result_t result = make_osp_result
Expand Down Expand Up @@ -4006,9 +4023,10 @@ prepare_osp_scan_for_resume (task_t task, const char *scan_id, char **error)
}
}
else if (status == OSP_SCAN_STATUS_RUNNING
|| status == OSP_SCAN_STATUS_QUEUED
|| status == OSP_SCAN_STATUS_FINISHED)
{
g_debug ("%s: Scan %s running or finished", __func__, scan_id);
g_debug ("%s: Scan %s queued, running or finished", __func__, scan_id);
/* It would be possible to simply continue getting the results
* from the scanner, but gvmd may have crashed while receiving
* or storing the results, so some may be missing. */
Expand Down Expand Up @@ -5736,7 +5754,8 @@ stop_task_internal (task_t task)

run_status = task_run_status (task);
if (run_status == TASK_STATUS_REQUESTED
|| run_status == TASK_STATUS_RUNNING)
|| run_status == TASK_STATUS_RUNNING
|| run_status == TASK_STATUS_QUEUED)
{
set_task_run_status (task, TASK_STATUS_STOP_REQUESTED);
return 1;
Expand Down Expand Up @@ -5914,6 +5933,7 @@ move_task (const char *task_id, const char *slave_id)
return 5;
break;
case TASK_STATUS_RUNNING:
case TASK_STATUS_QUEUED:
if (task_scanner_type == SCANNER_TYPE_CVE)
return 6;
// Check permissions to stop and resume task
Expand Down
3 changes: 2 additions & 1 deletion src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ typedef enum
TASK_STATUS_DELETE_ULTIMATE_REQUESTED = 14,
TASK_STATUS_STOP_REQUESTED_GIVEUP = 15,
TASK_STATUS_DELETE_WAITING = 16,
TASK_STATUS_DELETE_ULTIMATE_WAITING = 17
TASK_STATUS_DELETE_ULTIMATE_WAITING = 17,
TASK_STATUS_QUEUED = 18
} task_status_t;

/**
Expand Down
10 changes: 7 additions & 3 deletions src/manage_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ manage_create_sql_functions ()
" WHEN (SELECT scan_run_status FROM reports"
" WHERE reports.id = $1)"
" IN (SELECT unnest (ARRAY [%i, %i, %i, %i, %i, %i,"
" %i, %i]))"
" %i, %i, %i]))"
" THEN true"
" ELSE false"
" END;"
Expand All @@ -952,7 +952,8 @@ manage_create_sql_functions ()
TASK_STATUS_STOP_REQUESTED,
TASK_STATUS_STOP_REQUESTED_GIVEUP,
TASK_STATUS_STOPPED,
TASK_STATUS_INTERRUPTED);
TASK_STATUS_INTERRUPTED,
TASK_STATUS_QUEUED);

sql ("CREATE OR REPLACE FUNCTION report_progress (integer)"
" RETURNS integer AS $$"
Expand Down Expand Up @@ -1324,6 +1325,8 @@ manage_create_sql_functions ()
" THEN 'Stop Requested'"
" WHEN $1 = %i"
" THEN 'Stopped'"
" WHEN $1 = %i"
" THEN 'Queued'"
" ELSE 'Interrupted'"
" END;"
"$$ LANGUAGE SQL"
Expand All @@ -1339,7 +1342,8 @@ manage_create_sql_functions ()
TASK_STATUS_STOP_REQUESTED_GIVEUP,
TASK_STATUS_STOP_REQUESTED,
TASK_STATUS_STOP_WAITING,
TASK_STATUS_STOPPED);
TASK_STATUS_STOPPED,
TASK_STATUS_QUEUED);

if (sql_int ("SELECT EXISTS (SELECT * FROM information_schema.tables"
" WHERE table_catalog = '%s'"
Expand Down
25 changes: 20 additions & 5 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -2796,6 +2796,7 @@ keyword_applies_to_column (keyword_t *keyword, const char* column)
&& (strstr ("Done", keyword->string) == NULL)
&& (strstr ("New", keyword->string) == NULL)
&& (strstr ("Running", keyword->string) == NULL)
&& (strstr ("Queued", keyword->string) == NULL)
&& (strstr ("Stop Requested", keyword->string) == NULL)
&& (strstr ("Stopped", keyword->string) == NULL)
&& (strstr ("Interrupted", keyword->string) == NULL))
Expand Down Expand Up @@ -15225,6 +15226,7 @@ task_in_use (task_t task)
|| status == TASK_STATUS_DELETE_ULTIMATE_WAITING
|| status == TASK_STATUS_REQUESTED
|| status == TASK_STATUS_RUNNING
|| status == TASK_STATUS_QUEUED
|| status == TASK_STATUS_STOP_REQUESTED_GIVEUP
|| status == TASK_STATUS_STOP_REQUESTED
|| status == TASK_STATUS_STOP_WAITING;
Expand Down Expand Up @@ -16342,6 +16344,7 @@ stop_active_tasks ()
case TASK_STATUS_DELETE_WAITING:
case TASK_STATUS_REQUESTED:
case TASK_STATUS_RUNNING:
case TASK_STATUS_QUEUED:
case TASK_STATUS_STOP_REQUESTED_GIVEUP:
case TASK_STATUS_STOP_REQUESTED:
case TASK_STATUS_STOP_WAITING:
Expand Down Expand Up @@ -16377,6 +16380,7 @@ stop_active_tasks ()
" OR scan_run_status = %u"
" OR scan_run_status = %u"
" OR scan_run_status = %u"
" OR scan_run_status = %u"
" OR scan_run_status = %u;",
TASK_STATUS_INTERRUPTED,
TASK_STATUS_DELETE_REQUESTED,
Expand All @@ -16385,6 +16389,7 @@ stop_active_tasks ()
TASK_STATUS_DELETE_WAITING,
TASK_STATUS_REQUESTED,
TASK_STATUS_RUNNING,
TASK_STATUS_QUEUED,
TASK_STATUS_STOP_REQUESTED,
TASK_STATUS_STOP_REQUESTED_GIVEUP,
TASK_STATUS_STOP_WAITING);
Expand Down Expand Up @@ -17822,6 +17827,7 @@ set_task_requested (task_t task, task_status_t *status)
run_status = task_run_status (task);
if (run_status == TASK_STATUS_REQUESTED
|| run_status == TASK_STATUS_RUNNING
|| run_status == TASK_STATUS_QUEUED
|| run_status == TASK_STATUS_STOP_REQUESTED
|| run_status == TASK_STATUS_STOP_REQUESTED_GIVEUP
|| run_status == TASK_STATUS_STOP_WAITING
Expand Down Expand Up @@ -17895,13 +17901,16 @@ task_running_report (task_t task)
{
task_status_t run_status = task_run_status (task);
if (run_status == TASK_STATUS_REQUESTED
|| run_status == TASK_STATUS_RUNNING)
|| run_status == TASK_STATUS_RUNNING
|| run_status == TASK_STATUS_QUEUED)
{
return (unsigned int) sql_int ("SELECT max(id) FROM reports"
" WHERE task = %llu AND end_time IS NULL"
" AND scan_run_status = %u;",
" AND (scan_run_status = %u "
" OR scan_run_status = %u);",
task,
TASK_STATUS_RUNNING);
TASK_STATUS_RUNNING,
TASK_STATUS_QUEUED);
}
return (report_t) 0;
}
Expand All @@ -17920,6 +17929,7 @@ task_iterator_current_report (iterator_t *iterator)
task_status_t run_status = task_iterator_run_status (iterator);
if (run_status == TASK_STATUS_REQUESTED
|| run_status == TASK_STATUS_RUNNING
|| run_status == TASK_STATUS_QUEUED
|| run_status == TASK_STATUS_DELETE_REQUESTED
|| run_status == TASK_STATUS_DELETE_ULTIMATE_REQUESTED
|| run_status == TASK_STATUS_STOP_REQUESTED
Expand All @@ -17936,10 +17946,12 @@ task_iterator_current_report (iterator_t *iterator)
" OR scan_run_status = %u"
" OR scan_run_status = %u"
" OR scan_run_status = %u"
" OR scan_run_status = %u"
" OR scan_run_status = %u);",
task,
TASK_STATUS_REQUESTED,
TASK_STATUS_RUNNING,
TASK_STATUS_QUEUED,
TASK_STATUS_DELETE_REQUESTED,
TASK_STATUS_DELETE_ULTIMATE_REQUESTED,
TASK_STATUS_STOP_REQUESTED,
Expand Down Expand Up @@ -24583,9 +24595,10 @@ delete_report_internal (report_t report)
if (sql_int ("SELECT count(*) FROM reports WHERE id = %llu"
" AND (scan_run_status = %u OR scan_run_status = %u"
" OR scan_run_status = %u OR scan_run_status = %u"
" OR scan_run_status = %u);",
" OR scan_run_status = %u OR scan_run_status = %u);",
report,
TASK_STATUS_RUNNING,
TASK_STATUS_QUEUED,
TASK_STATUS_REQUESTED,
TASK_STATUS_DELETE_REQUESTED,
TASK_STATUS_DELETE_ULTIMATE_REQUESTED,
Expand Down Expand Up @@ -41730,7 +41743,8 @@ task_schedule_iterator_stop_due (iterator_t* iterator)
run_status = task_run_status (task_schedule_iterator_task (iterator));

if (run_status == TASK_STATUS_RUNNING
|| run_status == TASK_STATUS_REQUESTED)
|| run_status == TASK_STATUS_REQUESTED
|| run_status == TASK_STATUS_QUEUED)
{
time_t now, start;

Expand Down Expand Up @@ -52379,6 +52393,7 @@ delete_user (const char *user_id_arg, const char *name_arg, int ultimate,
case TASK_STATUS_DELETE_WAITING:
case TASK_STATUS_REQUESTED:
case TASK_STATUS_RUNNING:
case TASK_STATUS_QUEUED:
case TASK_STATUS_STOP_REQUESTED_GIVEUP:
case TASK_STATUS_STOP_REQUESTED:
case TASK_STATUS_STOP_WAITING:
Expand Down