Skip to content

Commit 888d271

Browse files
committed
Change: before starting ospd-openvas cleanup data-pickle-files
In some circumstances it can happen that the data-pickle files are not properly removed; for this cases they should be cleaned up before ospd-openvas starts.
1 parent 5c19960 commit 888d271

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

ospd/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ def main(
149149
signal.signal(
150150
signal.SIGINT, partial(exit_cleanup, args.pid_file, server, daemon)
151151
)
152+
signal.signal(
153+
signal.SIGQUIT, partial(exit_cleanup, args.pid_file, server, daemon)
154+
)
152155
if not daemon.check():
153156
return 1
154157

ospd/ospd.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
"""
2222

2323
import logging
24+
import multiprocessing
25+
import os
26+
from pathlib import Path
27+
import re
2428
import socket
2529
import ssl
26-
import multiprocessing
2730
import time
28-
import os
2931

3032
from pprint import pformat
3133
from typing import (
@@ -91,6 +93,11 @@ def _terminate_process_group(process: multiprocessing.Process) -> None:
9193
os.killpg(os.getpgid(process.pid), 15)
9294

9395

96+
is_uuid_re = re.compile(
97+
'^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
98+
)
99+
100+
94101
class OSPDaemon:
95102

96103
"""Daemon class for OSP traffic handling.
@@ -122,8 +129,18 @@ def __init__(
122129
**kwargs,
123130
): # pylint: disable=unused-argument
124131
"""Initializes the daemon's internal data."""
132+
133+
def remove_previous_data_pickler_files():
134+
logger.debug("removing uuid files in %s", file_storage_dir)
135+
root = Path(file_storage_dir)
136+
for dp in root.glob('*'):
137+
if is_uuid_re.match(dp.name):
138+
dp.unlink(missing_ok=True)
139+
return
140+
125141
self.scan_collection = ScanCollection(file_storage_dir)
126142
self.scan_processes = dict()
143+
remove_previous_data_pickler_files()
127144

128145
self.daemon_info = dict()
129146
self.daemon_info['name'] = "OSPd"

0 commit comments

Comments
 (0)