diff options
author | 2015-10-10 15:10:10 -0400 | |
---|---|---|
committer | 2015-10-10 15:10:10 -0400 | |
commit | 438ed1265ea9b4b7957d4b3b098abab6a37ebb5a (patch) | |
tree | 1f46aaa216aa7bafa0f5dfc0e4c50ef15eb0a26a /grs | |
parent | grs/Interpret.py: fix minor errors. (diff) | |
download | grss-438ed1265ea9b4b7957d4b3b098abab6a37ebb5a.tar.gz grss-438ed1265ea9b4b7957d4b3b098abab6a37ebb5a.tar.bz2 grss-438ed1265ea9b4b7957d4b3b098abab6a37ebb5a.zip |
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.
Diffstat (limited to 'grs')
-rw-r--r-- | grs/Execute.py | 23 | ||||
-rw-r--r-- | 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) |