Skip to content

Commit

Permalink
Restore SIGPIPE default action for subprocesses
Browse files Browse the repository at this point in the history
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 cinder.utils.execute and cinder-rootwrap
created subprocesses.

Fixes bug 1053364

Change-Id: I4b3307bd2f0f5d0da529d8b7d80fabae28c57732
  • Loading branch information
ttx authored and Chuck Short committed Oct 5, 2012
1 parent 7a158d2 commit d12d4b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bin/cinder-rootwrap
Expand Up @@ -34,6 +34,7 @@

import ConfigParser
import os
import signal
import subprocess
import sys

Expand All @@ -42,6 +43,13 @@ RC_UNAUTHORIZED = 99
RC_NOCOMMAND = 98
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)
Expand Down Expand Up @@ -77,6 +85,7 @@ if __name__ == '__main__':
stdin=sys.stdin,
stdout=sys.stdout,
stderr=sys.stderr,
preexec_fn=_subprocess_setup,
env=filtermatch.get_environment(userargs))
obj.wait()
sys.exit(obj.returncode)
Expand Down
8 changes: 8 additions & 0 deletions cinder/utils.py
Expand Up @@ -33,6 +33,7 @@
import re
import shlex
import shutil
import signal
import socket
import struct
import sys
Expand Down Expand Up @@ -90,6 +91,12 @@ def fetchfile(url, target):
execute('curl', '--fail', url, '-o', target)


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, **kwargs):
"""Helper method to execute command with optional retry.
Expand Down Expand Up @@ -160,6 +167,7 @@ def execute(*cmd, **kwargs):
stdout=_PIPE,
stderr=_PIPE,
close_fds=True,
preexec_fn=_subprocess_setup,
shell=shell)
result = None
if process_input is not None:
Expand Down

0 comments on commit d12d4b6

Please sign in to comment.