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

Fix resume task. #1679

Merged
merged 3 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Deprecated
### Removed
### Fixed
- Fix resume task. [#1679](https://github.com/greenbone/gvmd/pull/1679)


[Unreleased]: https://github.com/greenbone/gvmd/compare/v21.4.3...HEAD

Expand Down
27 changes: 25 additions & 2 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,15 @@ prepare_osp_scan_for_resume (task_t task, const char *scan_id, char **error)
}
status = osp_get_scan_status_ext (connection, status_opts, error);

/* Reset connection. */
osp_connection_close (connection);
connection = osp_scanner_connect (task_scanner (task));
if (!connection)
{
*error = g_strdup ("Could not connect to Scanner");
return -1;
}

if (status == OSP_SCAN_STATUS_ERROR)
{
if (g_str_has_prefix (*error, "Failed to find scan"))
Expand All @@ -2378,8 +2387,7 @@ 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)
|| status == OSP_SCAN_STATUS_QUEUED)
{
g_debug ("%s: Scan %s queued, running or finished", __func__, scan_id);
timopollmeier marked this conversation as resolved.
Show resolved Hide resolved
/* It would be possible to simply continue getting the results
Expand All @@ -2400,6 +2408,21 @@ prepare_osp_scan_for_resume (task_t task, const char *scan_id, char **error)
trim_partial_report (global_current_report);
return 1;
}
else if (status == OSP_SCAN_STATUS_FINISHED)
{
/* OSP can't stop an already finished/interrupted scan,
* but it must be delete to be resumed. */
g_debug ("%s: Scan %s finished", __func__, scan_id);
if (osp_delete_scan (connection, scan_id))
{
*error = g_strdup ("Failed to delete old report");
osp_connection_close (connection);
return -1;
}
osp_connection_close (connection);
trim_partial_report (global_current_report);
return 1;
}
else if (status == OSP_SCAN_STATUS_STOPPED)
{
g_debug ("%s: Scan %s stopped", __func__, scan_id);
Expand Down