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 19efb03e7eb5f7d4fa367b9861af8442554acb9c..e5d4e0005092b3e7ebf842788c17d44145bfa7c4 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 6b87da9f63919f64979e3bf8680bc361a99abdc3..d0cc79902753286e2afa0c254297094e5c73de8d 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 9c61b7bfa3fe0a2d4194b9cb3def60367efb0d77..bdd893c8e33feaba3e044f4f083b0090db94af07 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()