diff options
author | skyostil@chromium.org <skyostil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-17 12:03:12 +0000 |
---|---|---|
committer | skyostil@chromium.org <skyostil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-17 12:03:12 +0000 |
commit | 33369f5cf47a25f111b2d96db654da55edf40b7c (patch) | |
tree | 10957a3d8a6d6fc7862bbcc37656e8a3d2b16c72 /tools/cr | |
parent | 1b9608e5e774adcfc7c6d1b514194f9bb38efee6 (diff) | |
download | chromium_src-33369f5cf47a25f111b2d96db654da55edf40b7c.zip chromium_src-33369f5cf47a25f111b2d96db654da55edf40b7c.tar.gz chromium_src-33369f5cf47a25f111b2d96db654da55edf40b7c.tar.bz2 |
cr: Ignore Ctrl-C while running shell programs
While running programs in an interactive subshell (cr shell), ignore
Ctrl-C in cr itself. This lets the child program handle Ctrl-C the best
way it sees fit without always terminating cr.
TEST=cr shell gdb # Press Ctrl-C => Neither gdb nor cr terminates.
NOTRY=true
Review URL: https://codereview.chromium.org/167373003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251662 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/cr')
-rw-r--r-- | tools/cr/cr/base/host.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/tools/cr/cr/base/host.py b/tools/cr/cr/base/host.py index 745e15f..b8fb296 100644 --- a/tools/cr/cr/base/host.py +++ b/tools/cr/cr/base/host.py @@ -6,6 +6,7 @@ import os import pipes +import signal import subprocess import cr @@ -42,7 +43,8 @@ class Host(cr.Plugin, cr.Plugin.Type): def _Execute(self, context, command, shell=False, capture=False, silent=False, - ignore_dry_run=False, return_status=False): + ignore_dry_run=False, return_status=False, + ignore_interrupt_signal=False): """This is the only method that launches external programs. It is a thin wrapper around subprocess.Popen that handles cr specific @@ -58,6 +60,9 @@ class Host(cr.Plugin, cr.Plugin.Type): the command to be run anyway. return_status: switches the function to returning the status code rather the output. + ignore_interrupt_signal: Ignore the interrupt signal (i.e., Ctrl-C) while + the command is running. Useful for letting interactive programs manage + Ctrl-C by themselves. Returns: the status if return_status is true, or the output if capture is true, otherwise nothing. @@ -94,12 +99,12 @@ class Host(cr.Plugin, cr.Plugin.Type): print ' ', key, '=', value exit(1) try: + if ignore_interrupt_signal: + signal.signal(signal.SIGINT, signal.SIG_IGN) output, _ = p.communicate() - except KeyboardInterrupt: - p.terminate() - p.wait() - exit(1) finally: + if ignore_interrupt_signal: + signal.signal(signal.SIGINT, signal.SIG_DFL) if silent: out.close() if return_status: @@ -113,7 +118,8 @@ class Host(cr.Plugin, cr.Plugin.Type): @cr.Plugin.activemethod def Shell(self, context, *command): command = ' '.join([pipes.quote(arg) for arg in command]) - return self._Execute(context, [command], shell=True) + return self._Execute(context, [command], shell=True, + ignore_interrupt_signal=True) @cr.Plugin.activemethod def Execute(self, context, *command): |