OpenSCAP / openscap-daemon

Manages continuous scans of your infrastructure
https://www.open-scap.org/tools/openscap-daemon
GNU Lesser General Public License v2.1
106 stars 32 forks source link

Daemon fails to start when configuration file is invalid #66

Closed jan-cerny closed 8 years ago

jan-cerny commented 8 years ago

If /etc/oscapd/config.ini contains some nonsense, the deamon fails to start and gives a traceback. I think we should catch the exception, add an error message into journal and continue without trying to parse the configuration file.

Here is the traceback:

Starting OpenSCAP Daemon...
INFO:OpenSCAP Daemon 0.1.3
Started OpenSCAP Daemon.
DEBUG:Initialized AsyncManager, 4 workers
INFO:Loading configuration from '/etc/oscapd/config.ini'.
detected unhandled Python exception in '/usr/bin/oscapd'
Traceback (most recent call last):
File "/usr/bin/oscapd", line 70, in <module>
main()
File "/usr/bin/oscapd", line 64, in main
obj = dbus_daemon.OpenSCAPDaemonDbus(bus, config_file)
File "/usr/lib/python3.4/site-packages/openscap_daemon/dbus_daemon.py", line 42, in __init__
self.system = system.System(config_file)
File "/usr/lib/python3.4/site-packages/openscap_daemon/system.py", line 47, in __init__
self.config.load(config_file)
File "/usr/lib/python3.4/site-packages/openscap_daemon/config.py", line 154, in load
config.read(config_file)
File "/usr/lib64/python3.4/configparser.py", line 672, in read
self._read(fp, filename)
File "/usr/lib64/python3.4/configparser.py", line 1058, in _read
raise MissingSectionHeaderError(fpname, lineno, line)
configparser.MissingSectionHeaderError: File contains no section headers.
file: '/etc/oscapd/config.ini', line: 1 
'faoghaio\n'
mpreisler commented 8 years ago

I strongly disagree. This is not a bug, this is expected behavior. Invalid config files should cause hard loud fails of the daemon so somebody actually notices them.

What we should do is catch the configparser exception and wrap it in an exception explaining that the file is invalid and you should fix it. We definitely shouldn't continue starting the daemon with invalid config.