summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Lagun <slagun@mirantis.com>2016-03-22 16:47:49 +0300
committerStan Lagun <slagun@mirantis.com>2016-03-22 14:19:31 +0000
commit0bbfed3bf40192f34607c69c0a46301e81a643be (patch)
treef33f18ee99f60755a0d65f5784a61b2334801897
parent6def6725ed4d2da1f0e36d37456ce04219262926 (diff)
Restores SIGPIPE on script processesliberty-eol
There is an issue https://bugs.python.org/issue1652 in Python 2.7 which was resolved in Py3. By default Python sets SIGPIPE to SIG_IGN on startup, because it prefers to check every write and raise an IOError exception rather than taking SIGPIPE. This is all well and good for Python itself. However, non-Python Unix subprocesses generally expect to have SIGPIPE set to the default action, since that's what will happen if they're started from a normal shell. As a result scripts with piping that is terminated in reverse chain order are never exit. See more info here: http://www.enricozini.org/blog/2009/debian/python-pipes/ Closes-Bug: #1524347 Change-Id: Ia015e7fd46912f6a0be97a6b9c297f8d14fd3f7c
Notes
Notes (review): Verified+1: Murano CI Code-Review+2: Kirill Zaitsev <kzaitsev@mirantis.com> Code-Review+2: Serg Melikyan <smelikyan@mirantis.com> Workflow+1: Serg Melikyan <smelikyan@mirantis.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Tue, 22 Mar 2016 16:05:54 +0000 Reviewed-on: https://review.openstack.org/295852 Project: openstack/murano-agent Branch: refs/heads/stable/liberty
-rw-r--r--muranoagent/executors/application/__init__.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/muranoagent/executors/application/__init__.py b/muranoagent/executors/application/__init__.py
index 5dba999..934e3cb 100644
--- a/muranoagent/executors/application/__init__.py
+++ b/muranoagent/executors/application/__init__.py
@@ -14,6 +14,7 @@
14# limitations under the License. 14# limitations under the License.
15 15
16import os 16import os
17import signal
17import stat 18import stat
18import subprocess 19import subprocess
19import sys 20import sys
@@ -52,13 +53,18 @@ class ApplicationExecutor(object):
52 script_name = os.path.relpath(self._path) 53 script_name = os.path.relpath(self._path)
53 LOG.debug("Starting '{0}' script execution".format(script_name)) 54 LOG.debug("Starting '{0}' script execution".format(script_name))
54 55
55 process = subprocess.Popen( 56 popen_kwargs = {
56 app, 57 'stdout': stdout,
57 stdout=stdout, 58 'stderr': stderr,
58 stderr=stderr, 59 'universal_newlines': True,
59 universal_newlines=True, 60 'cwd': dir_name,
60 cwd=dir_name, 61 'shell': True
61 shell=True) 62 }
63 if os.name != 'nt':
64 popen_kwargs['preexec_fn'] = lambda: signal.signal(
65 signal.SIGPIPE, signal.SIG_DFL)
66
67 process = subprocess.Popen(app, **popen_kwargs)
62 stdout, stderr = process.communicate(input) 68 stdout, stderr = process.communicate(input)
63 retcode = process.poll() 69 retcode = process.poll()
64 LOG.debug("Script {0} execution finished " 70 LOG.debug("Script {0} execution finished "