Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Improve/fix exit cleanup function #307

Merged
merged 3 commits into from
Jul 29, 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Make scan_id attribute mandatory for get_scans. [#270](https://github.com/greenbone/ospd/pull/270)
- Ignore subsequent SIGINT once inside exit_cleanup(). [#273](https://github.com/greenbone/ospd/pull/273)
- Simplify start_scan() [#275](https://github.com/greenbone/ospd/pull/275)
- Make ospd-openvas to shut down gracefully [#302](https://github.com/greenbone/ospd/pull/302)
- Make ospd-openvas to shut down gracefully
[#302](https://github.com/greenbone/ospd/pull/302)
[#307](https://github.com/greenbone/ospd/pull/307)

### Fixed
- Fix stop scan. Wait for the scan process to be stopped before delete it from the process table. [#204](https://github.com/greenbone/ospd/pull/204)
Expand Down
14 changes: 11 additions & 3 deletions ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,17 +440,25 @@ def daemon_exit_cleanup(self) -> None:
""" Perform a cleanup before exiting """
self.scan_collection.clean_up_pickled_scan_info()

# Stop scans which are not already stopped.
for scan_id in self.scan_collection.ids_iterator():
self.stop_scan(scan_id)
status = self.get_scan_status(scan_id)
if (
status != ScanStatus.STOPPED
and status != ScanStatus.FINISHED
and status != ScanStatus.INTERRUPTED
):
self.stop_scan(scan_id)

# Wait for scans to be in some stopped state.
while True:
all_stopped = True
for scan_id in self.scan_collection.ids_iterator():
status = self.get_scan_status(scan_id)
if (
status != ScanStatus.STOPPED
or status != ScanStatus.FINISHED
or status != ScanStatus.INTERRUPTED
and status != ScanStatus.FINISHED
and status != ScanStatus.INTERRUPTED
):
all_stopped = False

Expand Down