chiark / gitweb /
better config errors
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 Apr 2017 10:09:38 +0000 (11:09 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 Apr 2017 10:11:35 +0000 (11:11 +0100)
client
hippotat/__init__.py
server

diff --git a/client b/client
index 19efb03..e5d4e00 100755 (executable)
--- a/client
+++ b/client
@@ -230,8 +230,7 @@ def check_outbound():
 
   log_outstanding()
 
-common_startup()
-process_cfg()
+common_startup(process_cfg)
 start_client()
 start_ipif(c.ipif_command, outbound)
 check_outbound()
index 6b87da9..d0cc799 100644 (file)
@@ -20,6 +20,7 @@ import ipaddress
 from ipaddress import AddressValueError
 
 from optparse import OptionParser
+import configparser
 from configparser import ConfigParser
 from configparser import NoOptionError
 
@@ -403,7 +404,7 @@ def process_cfg_clients(constructor):
 
 #---------- startup ----------
 
-def common_startup():
+def common_startup(process_cfg):
   re = regexp.compile('#.*')
   cfg.read_string(re.sub('', defcfg))
   need_defcfg = True
@@ -514,6 +515,12 @@ just `+': all DFLAGs.
     readconfig('/etc/hippotat/config',   False)
     readconfig('/etc/hippotat/config.d', False)
 
+  try: process_cfg()
+  except (configparser.Error, ValueError):
+    traceback.print_exc(file=sys.stderr)
+    print('\nInvalid configuration, giving up.', file=sys.stderr)
+    sys.exit(12)
+
   #print(repr(debug_set), file=sys.stderr)
 
   log_formatter = twisted.logger.formatEventAsClassicLogText
diff --git a/server b/server
index 9c61b7b..bdd893c 100755 (executable)
--- a/server
+++ b/server
@@ -241,8 +241,7 @@ def process_cfg():
                     ('peer', 'relay'),
                     ('rnets','network')))
 
-common_startup()
-process_cfg()
+common_startup(process_cfg)
 start_ipif(c.ipif_command, (lambda p,s,d: route(p,"[ipif]",s,d)))
 start_http()
 common_run()