summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2021-02-25 20:50:16 -0600
committerJohn Estabrook <jestabro@vyos.io>2021-02-25 20:54:05 -0600
commit77a16626802aa1986daa0cbfdb05e0427e49ccd6 (patch)
treefda1f22bef307760f578ac776eae6331dc8b7de8 /src
parent1ac2e363013d0b04ea2eae66607e7c3e54aade92 (diff)
downloadvyos-1x-77a16626802aa1986daa0cbfdb05e0427e49ccd6.tar.gz
vyos-1x-77a16626802aa1986daa0cbfdb05e0427e49ccd6.zip
configd: T3302: set mode correctly on open for redirect
Diffstat (limited to 'src')
-rwxr-xr-xsrc/services/vyos-configd10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/services/vyos-configd b/src/services/vyos-configd
index 7aea77f5a..1e60e53df 100755
--- a/src/services/vyos-configd
+++ b/src/services/vyos-configd
@@ -63,6 +63,7 @@ configd_env_unset_file = os.path.join(directories['data'], 'vyos-configd-env-uns
configd_env_file = '/etc/default/vyos-configd-env'
session_out = None
+session_mode = None
def key_name_from_file_name(f):
return os.path.splitext(f)[0]
@@ -111,7 +112,7 @@ include_set = {key_name_from_file_name(f) for f in filenames if f in include}
def run_script(script, config) -> int:
config.set_level([])
try:
- with open(session_out, 'a') as f, redirect_stdout(f):
+ with open(session_out, session_mode) as f, redirect_stdout(f):
with redirect_stderr(f):
c = script.get_config(config)
script.verify(c)
@@ -119,7 +120,7 @@ def run_script(script, config) -> int:
script.apply(c)
except ConfigError as e:
logger.critical(e)
- with open(session_out, 'a') as f, redirect_stdout(f):
+ with open(session_out, session_mode) as f, redirect_stdout(f):
print(f"{e}\n")
return R_ERROR_COMMIT
except Exception as e:
@@ -130,6 +131,7 @@ def run_script(script, config) -> int:
def initialization(socket):
global session_out
+ global session_mode
# Reset config strings:
active_string = ''
session_string = ''
@@ -158,12 +160,14 @@ def initialization(socket):
logger.debug(f"config session pid is {pid_string}")
try:
session_out = os.readlink(f"/proc/{pid_string}/fd/1")
+ session_mode = 'w'
except FileNotFoundError:
session_out = None
# if not a 'live' session, for example on boot, write to file
- if '/dev/pts' not in session_out:
+ if not session_out or '/dev/pts' not in session_out:
session_out = script_stdout_log
+ session_mode = 'a'
try:
configsource = ConfigSourceString(running_config_text=active_string,