Python ignores SIGPIPE on startup, because it prefers to check every
write and raise an IOError exception rather than taking the signal. Most
Unix subprocesses don't expect to work this way. This patch (adapted
from Colin Watson's post at http://tinyurl.com/2a7mzh5) sets SIGPIPE
back to the default action for quantum.agent.linux.utils.execute,
quantum.common.utils.execute and quantum-rootwrap created subprocesses.
Fixes bug
1053364
Change-Id: Ib805f1f8846c245b75a5ea64278c840b823c1fb2
import ConfigParser
import os
+import signal
import subprocess
import sys
RC_BADCONFIG = 97
+def _subprocess_setup():
+ # Python installs a SIGPIPE handler by default. This is usually not what
+ # non-Python subprocesses expect.
+ signal.signal(signal.SIGPIPE, signal.SIG_DFL)
+
+
if __name__ == '__main__':
# Split arguments, require at least a command
execname = sys.argv.pop(0)
stdin=sys.stdin,
stdout=sys.stdout,
stderr=sys.stderr,
+ preexec_fn=_subprocess_setup,
env=filtermatch.get_environment(userargs))
obj.wait()
sys.exit(obj.returncode)
import logging
import os
import shlex
+import signal
import socket
import struct
LOG = logging.getLogger(__name__)
+def _subprocess_setup():
+ # Python installs a SIGPIPE handler by default. This is usually not what
+ # non-Python subprocesses expect.
+ signal.signal(signal.SIGPIPE, signal.SIG_DFL)
+
+
def execute(cmd, root_helper=None, process_input=None, addl_env=None,
check_exit_code=True, return_stderr=False):
if root_helper:
env.update(addl_env)
obj = subprocess.Popen(cmd, shell=False, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ preexec_fn=_subprocess_setup,
env=env)
_stdout, _stderr = (process_input and
import logging
import os
+import signal
import subprocess
import uuid
return subject
+def _subprocess_setup():
+ # Python installs a SIGPIPE handler by default. This is usually not what
+ # non-Python subprocesses expect.
+ signal.signal(signal.SIGPIPE, signal.SIG_DFL)
+
+
def execute(cmd, process_input=None, addl_env=None, check_exit_code=True):
logging.debug("Running cmd: %s", cmd)
env = os.environ.copy()
env.update(addl_env)
obj = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ preexec_fn=_subprocess_setup,
env=env)
result = None
if process_input is not None: