From dd7eca86d8d9c80d5e1915d97765e1d69207093b Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Wed, 3 Mar 2021 17:10:26 +0100 Subject: [PATCH 1/2] Update report run status more consistently To ensure the task status changes in fork_osp_scan_handler, stop_osp_task and stop_task_internal also update the report status before events are triggered, they will set current_scanner_task and global_current_report temporarily / within the forked process. --- src/manage.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/manage.c b/src/manage.c index ad4181cc0..c7131d2d5 100644 --- a/src/manage.c +++ b/src/manage.c @@ -4508,6 +4508,7 @@ fork_osp_scan_handler (task_t task, target_t target, int from, if (run_osp_scan_get_report (task, from, &report_id)) return -1; + current_scanner_task = task; set_task_run_status (task, TASK_STATUS_REQUESTED); switch (fork ()) @@ -4526,11 +4527,13 @@ fork_osp_scan_handler (task_t task, target_t target, int from, set_report_scan_run_status (global_current_report, TASK_STATUS_INTERRUPTED); global_current_report = (report_t) 0; + current_scanner_task = 0; g_free (report_id); return -9; default: /* Parent, successfully forked. */ global_current_report = 0; + current_scanner_task = 0; if (report_id_return) *report_id_return = report_id; else @@ -5757,6 +5760,11 @@ stop_osp_task (task_t task) int ret = -1; report_t scan_report; char *scan_id; + task_t previous_task; + report_t previous_report; + + previous_task = current_scanner_task; + previous_report = global_current_report; scan_report = task_running_report (task); scan_id = report_uuid (scan_report); @@ -5765,6 +5773,9 @@ stop_osp_task (task_t task) connection = osp_scanner_connect (task_scanner (task)); if (!connection) goto end_stop_osp; + + current_scanner_task = task; + global_current_report = task_running_report (task); set_task_run_status (task, TASK_STATUS_STOP_REQUESTED); ret = osp_stop_scan (connection, scan_id, NULL); osp_connection_close (connection); @@ -5789,6 +5800,8 @@ stop_osp_task (task_t task) set_scan_end_time_epoch (scan_report, time (NULL)); set_report_scan_run_status (scan_report, TASK_STATUS_STOPPED); } + current_scanner_task = previous_task; + global_current_report = previous_report; if (ret) return -1; return 0; @@ -5805,13 +5818,22 @@ int stop_task_internal (task_t task) { task_status_t run_status; + task_t previous_task; + report_t previous_report; + + previous_task = current_scanner_task; + previous_report = global_current_report; run_status = task_run_status (task); if (run_status == TASK_STATUS_REQUESTED || run_status == TASK_STATUS_RUNNING || run_status == TASK_STATUS_QUEUED) { + current_scanner_task = task; + global_current_report = task_running_report (task); set_task_run_status (task, TASK_STATUS_STOP_REQUESTED); + current_scanner_task = previous_task; + global_current_report = previous_report; return 1; } else if (run_status == TASK_STATUS_DELETE_REQUESTED @@ -5829,7 +5851,11 @@ stop_task_internal (task_t task) { /* A special request from the user to get the task out of a requested * state when contact with the slave is lost. */ + current_scanner_task = task; + task_last_report (task, &global_current_report); set_task_run_status (task, TASK_STATUS_STOP_REQUESTED_GIVEUP); + current_scanner_task = previous_task; + global_current_report = previous_report; return 1; } } From dc54e17f4fa78276971d8c83241771ce7dd17e1c Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Wed, 3 Mar 2021 17:22:18 +0100 Subject: [PATCH 2/2] Add report status fix to CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59e722440..e9b4d4a9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Also create owner WITH clause for single resources [#1406](https://github.com/greenbone/gvmd/pull/1406) - Fix SQL escaping when adding VT references [#1429](https://github.com/greenbone/gvmd/pull/1429) +- Update report run status more consistently [#1434](https://github.com/greenbone/gvmd/pull/1434) ### Removed