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

Update report run status more consistently #1434

Merged
merged 3 commits into from
Mar 8, 2021
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 @@ -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)
- Improve modify_override errors, fix no NVT case [#1435](https://github.com/greenbone/gvmd/pull/1435)

### Removed
Expand Down
26 changes: 26 additions & 0 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ())
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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;
}
}
Expand Down