From 9fe4591d0897b66c3a92099b7b956f24cbcdae4b Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Wed, 7 Oct 2015 21:44:51 +0200 Subject: [PATCH] (configd) send (part of) stderr to syslog for script_output tasks --- .../service/modules/processhandler.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/opnsense/service/modules/processhandler.py b/src/opnsense/service/modules/processhandler.py index 8a1c43a2c..2ba00006c 100644 --- a/src/opnsense/service/modules/processhandler.py +++ b/src/opnsense/service/modules/processhandler.py @@ -24,7 +24,6 @@ POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------------- - package : configd function: unix domain socket process worker process """ @@ -457,12 +456,19 @@ class Action(object): return 'Execute error' elif self.type.lower() == 'script_output': try: - with tempfile.NamedTemporaryFile() as output_stream: - subprocess.check_call(script_command, env=self.config_environment, shell=True, - stdout=output_stream, stderr=subprocess.STDOUT) - output_stream.seek(0) - script_output = output_stream.read() - return script_output + with tempfile.NamedTemporaryFile() as error_stream: + with tempfile.NamedTemporaryFile() as output_stream: + subprocess.check_call(script_command, env=self.config_environment, shell=True, + stdout=output_stream, stderr=error_stream) + output_stream.seek(0) + error_stream.seek(0) + script_output = output_stream.read() + script_error_output = error_stream.read() + if len(script_error_output) > 0: + syslog.syslog(syslog.LOG_ERR, '[%s] Script action stderr returned "%s"' % (message_uuid, + script_error_output.strip()[:255]) + ) + return script_output except: syslog.syslog(syslog.LOG_ERR, '[%s] Script action failed at %s' % (message_uuid, traceback.format_exc()))