summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2021-02-17 19:31:29 -0600
committerJohn Estabrook <jestabro@vyos.io>2021-02-17 19:34:15 -0600
commit8f50b3dd94f41a11ce4d0bb06d3506caaf2864b8 (patch)
tree8d3088c605abd23759a7c4bee3d7f77a64391f57 /src/services
parent83bcd13775323bec35d018223029e9a8b13179c8 (diff)
downloadvyos-1x-8f50b3dd94f41a11ce4d0bb06d3506caaf2864b8.tar.gz
vyos-1x-8f50b3dd94f41a11ce4d0bb06d3506caaf2864b8.zip
configd: T3302: redirect stdout/stderr from scripts to console
Diffstat (limited to 'src/services')
-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