summaryrefslogtreecommitdiff
path: root/src/services/vyos-configd
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2021-02-22 17:04:15 +0200
committerDaniil Baturin <daniil@vyos.io>2021-02-22 17:04:15 +0200
commitbdc35ac8ad1d3d88c796aa488749e44bda617b44 (patch)
treeb2c97b7ab02aa6c3c3ed27cb98e46302f797c909 /src/services/vyos-configd
parent28cd2e3edb3e2108c43ad20c0084d496a7ffef25 (diff)
parentcf1156a60e1d03a752cde0baadbc9ac8118b2a52 (diff)
downloadvyos-1x-bdc35ac8ad1d3d88c796aa488749e44bda617b44.tar.gz
vyos-1x-bdc35ac8ad1d3d88c796aa488749e44bda617b44.zip
Merge branch 'current' of https://github.com/vyos/vyos-1x into current
Diffstat (limited to 'src/services/vyos-configd')
-rwxr-xr-xsrc/services/vyos-configd25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/services/vyos-configd b/src/services/vyos-configd
index 5b1ab1f1f..3bd516463 100755
--- a/src/services/vyos-configd
+++ b/src/services/vyos-configd
@@ -25,6 +25,7 @@ import logging
import signal
import importlib.util
import zmq
+from contextlib import redirect_stdout, redirect_stderr
from vyos.defaults import directories
from vyos.configsource import ConfigSourceString, ConfigSourceError
@@ -104,27 +105,23 @@ conf_mode_scripts = dict(zip(imports, modules))
exclude_set = {key_name_from_file_name(f) for f in filenames if f not in include}
include_set = {key_name_from_file_name(f) for f in filenames if f in include}
-def explicit_print(t, m):
- try:
- with open(t, 'w') as f:
- f.write(m)
- f.write("\n")
- f.flush()
- except Exception:
- pass
def run_script(script, config) -> int:
config.set_level([])
try:
- c = script.get_config(config)
- script.verify(c)
- script.generate(c)
- script.apply(c)
+ with open(session_tty, 'w') as f, redirect_stdout(f):
+ with redirect_stderr(f):
+ c = script.get_config(config)
+ script.verify(c)
+ script.generate(c)
+ script.apply(c)
except ConfigError as e:
logger.critical(e)
- explicit_print(session_tty, str(e))
+ with open(session_tty, 'w') as f, redirect_stdout(f):
+ print(f"{e}\n")
return R_ERROR_COMMIT
- except Exception:
+ except Exception as e:
+ logger.critical(e)
return R_ERROR_DAEMON
return R_SUCCESS