From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 52B5E13888F for ; Sat, 10 Oct 2015 19:07:11 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1DD9421C018; Sat, 10 Oct 2015 19:07:09 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A6C4721C018 for ; Sat, 10 Oct 2015 19:07:08 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 829F433E3A9 for ; Sat, 10 Oct 2015 19:07:04 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 1F7C0B9 for ; Sat, 10 Oct 2015 19:07:02 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <1444504210.438ed1265ea9b4b7957d4b3b098abab6a37ebb5a.blueness@gentoo> Subject: [gentoo-commits] proj/grss:master commit in: grs/ X-VCS-Repository: proj/grss X-VCS-Files: grs/Execute.py grs/Interpret.py X-VCS-Directories: grs/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: 438ed1265ea9b4b7957d4b3b098abab6a37ebb5a X-VCS-Branch: master Date: Sat, 10 Oct 2015 19:07:02 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: d20550cb-739e-44bb-8ca4-58d9c3f97a92 X-Archives-Hash: 96576a63850ead70eb906950d47930d9 commit: 438ed1265ea9b4b7957d4b3b098abab6a37ebb5a Author: Anthony G. Basile gentoo org> AuthorDate: Sat Oct 10 19:10:10 2015 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Sat Oct 10 19:10:10 2015 +0000 URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=438ed126 grs/Execute.py, Interpret.py: clean up signal code While the following may look like a good idea, its not: while True: os.kill(pid, signal.SIGKILL) If pid is zombied, we're stuck in an infinite loop. Rather for all processes in the cgroup we just aggressively send a SIGKILL until only the first ancestor remains. grs/Execute.py | 23 +++++++---------------- grs/Interpret.py | 18 +++--------------- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/grs/Execute.py b/grs/Execute.py index 0e70221..7b0e5a2 100644 --- a/grs/Execute.py +++ b/grs/Execute.py @@ -42,12 +42,6 @@ class Execute(): logfile - A file to log output to. If logfile = None, then we log to sys.stdout. """ - def signalexit(): - pid = os.getpid() - while True: - os.kill(pid, signal.SIGTERM) - time.sleep(2.0) - if shell: args = cmd else: @@ -71,19 +65,16 @@ class Execute(): if not timed_out: # _rc = None if we had a timeout _rc = proc.returncode - if _rc: - _file.write('EXIT CODE: %d\n' % _rc) - if not failok: - _file.write('SENDING SIGTERM\n') - _file.close() - signalexit() + _file.write('EXIT CODE: %d\n' % _rc) if timed_out: _file.write('TIMEOUT ERROR: %s\n' % cmd) - if not failok: - _file.write('SENDING SIGTERM\n') - _file.close() - signalexit() + + if not failok and ( _rc != 0 or timed_out): + pid = os.getpid() + _file.write('SENDING SIGTERM: %s\n' % pid) + _file.close() + os.kill(pid, signal.SIGTERM) # Only close a logfile, don't close sys.stderr! if logfile: diff --git a/grs/Interpret.py b/grs/Interpret.py index 3e2c408..5624fd4 100644 --- a/grs/Interpret.py +++ b/grs/Interpret.py @@ -64,12 +64,7 @@ class Interpret(Daemon): if mypid == pid: continue try: - for i in range(10): - os.kill(pid, signal.SIGTERM) - time.sleep(0.2) - while True: - os.kill(pid, signal.SIGKILL) - time.sleep(0.2) + os.kill(pid, signal.SIGKILL) except ProcessLookupError: pass try: @@ -79,13 +74,6 @@ class Interpret(Daemon): sys.exit(signum + 128) - def signalexit(): - pid = os.getpid() - while True: - os.kill(pid, signal.SIGTERM) - time.sleep(2.0) - - def semantic_action(_line, objs, nargs, func, *args): """ Execute the directive """ err = None @@ -104,7 +92,7 @@ class Interpret(Daemon): _lo.log('Bad command: %s' % _line) _lo.log('Error message: %s' % err) _lo.log('SENDING SIGTERM\n') - signalexit() + os.kill(os.getpid(), signal.SIGTERM) def stampit(progress): @@ -262,7 +250,7 @@ class Interpret(Daemon): _lo.log('Bad command: %s' % _line) _lo.log('Unknown verb: %s' % verb) _lo.log('SENDING SIGTERM\n') - signalexit() + os.kill(os.getpid(), signal.SIGTERM) stampit(progress)