diff options
author | Zac Medico <zmedico@gentoo.org> | 2011-01-15 19:43:35 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2011-01-15 19:43:35 -0800 |
commit | f707221b69ed913b7a1cb66c7ab45be2d1586f7c (patch) | |
tree | d45571c3576a17df3bbf50073544a0573599974c | |
parent | 3119eb0c7ae911e14f78624763cc79edfe953ad8 (diff) | |
download | portage-f707221b69ed913b7a1cb66c7ab45be2d1586f7c.tar.gz portage-f707221b69ed913b7a1cb66c7ab45be2d1586f7c.tar.bz2 portage-f707221b69ed913b7a1cb66c7ab45be2d1586f7c.zip |
Tweak PollScheduler signal handling.
-rwxr-xr-x | bin/egencache | 10 | ||||
-rw-r--r-- | pym/_emerge/Scheduler.py | 32 | ||||
-rw-r--r-- | pym/_emerge/actions.py | 38 |
3 files changed, 44 insertions, 36 deletions
diff --git a/bin/egencache b/bin/egencache index bf729c380..76dd900e7 100755 --- a/bin/egencache +++ b/bin/egencache @@ -272,15 +272,19 @@ class GenCache(object): try: self._regen.run() - - if received_signal: - sys.exit(received_signal[0]) finally: # Restore previous handlers if earlier_sigint_handler is not None: signal.signal(signal.SIGINT, earlier_sigint_handler) + else: + signal.signal(signal.SIGINT, signal.SIG_DFL) if earlier_sigterm_handler is not None: signal.signal(signal.SIGTERM, earlier_sigterm_handler) + else: + signal.signal(signal.SIGTERM, signal.SIG_DFL) + + if received_signal: + sys.exit(received_signal[0]) self.returncode |= self._regen.returncode cp_missing = self._cp_missing diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py index ac48f853e..463d0d85e 100644 --- a/pym/_emerge/Scheduler.py +++ b/pym/_emerge/Scheduler.py @@ -7,6 +7,7 @@ import gc import gzip import logging import shutil +import signal import sys import tempfile import textwrap @@ -1166,10 +1167,35 @@ class Scheduler(PollScheduler): return rval while True: - rval = self._merge() - if self._terminated.is_set(): - return 1 + received_signal = [] + + def sighandler(signum, frame): + signal.signal(signal.SIGINT, signal.SIG_IGN) + signal.signal(signal.SIGTERM, signal.SIG_IGN) + portage.util.writemsg("\n\nExiting on signal %(signal)s\n" % \ + {"signal":signum}) + self.terminate() + received_signal.append(128 + signum) + + earlier_sigint_handler = signal.signal(signal.SIGINT, sighandler) + earlier_sigterm_handler = signal.signal(signal.SIGTERM, sighandler) + + try: + rval = self._merge() + finally: + # Restore previous handlers + if earlier_sigint_handler is not None: + signal.signal(signal.SIGINT, earlier_sigint_handler) + else: + signal.signal(signal.SIGINT, signal.SIG_DFL) + if earlier_sigterm_handler is not None: + signal.signal(signal.SIGTERM, earlier_sigterm_handler) + else: + signal.signal(signal.SIGTERM, signal.SIG_DFL) + + if received_signal: + sys.exit(received_signal[0]) if rval == os.EX_OK or fetchonly or not keep_going: break diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index 25b5ab138..ee37bb821 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -147,7 +147,6 @@ def action_build(settings, trees, mtimedb, ldpath_mtimes = mtimedb["ldpath"] favorites=[] - merge_count = 0 buildpkgonly = "--buildpkgonly" in myopts pretend = "--pretend" in myopts fetchonly = "--fetchonly" in myopts or "--fetch-all-uri" in myopts @@ -435,32 +434,7 @@ def action_build(settings, trees, mtimedb, del mydepgraph clear_caches(trees) - received_signal = [] - - def emergeexitsig(signum, frame): - signal.signal(signal.SIGINT, signal.SIG_IGN) - signal.signal(signal.SIGTERM, signal.SIG_IGN) - portage.util.writemsg("\n\nExiting on signal %(signal)s\n" % \ - {"signal":signum}) - mergetask.terminate() - received_signal.append(128 + signum) - - earlier_sigint_handler = signal.signal(signal.SIGINT, emergeexitsig) - earlier_sigterm_handler = signal.signal(signal.SIGTERM, emergeexitsig) - - try: - retval = mergetask.merge() - - if received_signal: - sys.exit(received_signal[0]) - finally: - # Restore previous handlers - if earlier_sigint_handler is not None: - signal.signal(signal.SIGINT, earlier_sigint_handler) - if earlier_sigterm_handler is not None: - signal.signal(signal.SIGTERM, earlier_sigterm_handler) - - merge_count = mergetask.curval + retval = mergetask.merge() if retval == os.EX_OK and not (buildpkgonly or fetchonly or pretend): if "yes" == settings.get("AUTOCLEAN"): @@ -1853,15 +1827,19 @@ def action_regen(settings, portdb, max_jobs, max_load): try: regen.run() - - if received_signal: - sys.exit(received_signal[0]) finally: # Restore previous handlers if earlier_sigint_handler is not None: signal.signal(signal.SIGINT, earlier_sigint_handler) + else: + signal.signal(signal.SIGINT, signal.SIG_DFL) if earlier_sigterm_handler is not None: signal.signal(signal.SIGTERM, earlier_sigterm_handler) + else: + signal.signal(signal.SIGTERM, signal.SIG_DFL) + + if received_signal: + sys.exit(received_signal[0]) portage.writemsg_stdout("done!\n") return regen.returncode |