From bf1d6fff80eebb579f2c33b1352a7162b8474730 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Mon, 14 Sep 2020 15:41:22 -0500 Subject: configd: T2885: print commit errors to config session terminal --- src/services/vyos-configd | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/services') diff --git a/src/services/vyos-configd b/src/services/vyos-configd index 75f84d3df..579605e8c 100755 --- a/src/services/vyos-configd +++ b/src/services/vyos-configd @@ -62,6 +62,8 @@ configd_env_file = '/etc/default/vyos-configd-env' active_string = '' session_string = '' +session_tty = None + def key_name_from_file_name(f): return os.path.splitext(f)[0] @@ -105,6 +107,13 @@ 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.flush() + except Exception: + pass def run_script(script, config) -> int: config.set_level([]) @@ -115,6 +124,7 @@ def run_script(script, config) -> int: script.apply(c) except ConfigError as e: logger.critical(e) + explicit_print(session_tty, e) return R_ERROR_COMMIT except Exception: return R_ERROR_DAEMON @@ -132,6 +142,15 @@ def initialization(socket): session_string = socket.recv().decode() resp = "session" socket.send(resp.encode()) + pid_string = socket.recv().decode() + resp = "pid" + socket.send(resp.encode()) + + logger.debug(f"config session pid is {pid_string}") + try: + session_tty = os.readlink(f"/proc/{pid_string}/fd/1") + except FileNotFoundError: + session_tty = None configsource = ConfigSourceString(running_config_text=active_string, session_config_text=session_string) -- cgit v1.2.3 From 6ac916ecd58cf1515dd5b9b47283d5528d0c265b Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 16 Sep 2020 11:24:16 -0500 Subject: configd: T2885: fix output of error string to config session --- src/services/vyos-configd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/services') diff --git a/src/services/vyos-configd b/src/services/vyos-configd index 579605e8c..642952936 100755 --- a/src/services/vyos-configd +++ b/src/services/vyos-configd @@ -111,6 +111,7 @@ def explicit_print(t, m): try: with open(t, 'w') as f: f.write(m) + f.write("\n") f.flush() except Exception: pass @@ -124,7 +125,7 @@ def run_script(script, config) -> int: script.apply(c) except ConfigError as e: logger.critical(e) - explicit_print(session_tty, e) + explicit_print(session_tty, str(e)) return R_ERROR_COMMIT except Exception: return R_ERROR_DAEMON @@ -132,6 +133,7 @@ def run_script(script, config) -> int: return R_SUCCESS def initialization(socket): + global session_tty # Reset config strings: active_string = '' session_string = '' -- cgit v1.2.3