1 |
commit: 438ed1265ea9b4b7957d4b3b098abab6a37ebb5a |
2 |
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Oct 10 19:10:10 2015 +0000 |
4 |
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Oct 10 19:10:10 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=438ed126 |
7 |
|
8 |
grs/Execute.py, Interpret.py: clean up signal code |
9 |
|
10 |
While the following may look like a good idea, its not: |
11 |
|
12 |
while True: |
13 |
os.kill(pid, signal.SIGKILL) |
14 |
|
15 |
If pid is zombied, we're stuck in an infinite loop. Rather |
16 |
for all processes in the cgroup we just aggressively send a |
17 |
SIGKILL until only the first ancestor remains. |
18 |
|
19 |
grs/Execute.py | 23 +++++++---------------- |
20 |
grs/Interpret.py | 18 +++--------------- |
21 |
2 files changed, 10 insertions(+), 31 deletions(-) |
22 |
|
23 |
diff --git a/grs/Execute.py b/grs/Execute.py |
24 |
index 0e70221..7b0e5a2 100644 |
25 |
--- a/grs/Execute.py |
26 |
+++ b/grs/Execute.py |
27 |
@@ -42,12 +42,6 @@ class Execute(): |
28 |
logfile - A file to log output to. If logfile = None, then we log |
29 |
to sys.stdout. |
30 |
""" |
31 |
- def signalexit(): |
32 |
- pid = os.getpid() |
33 |
- while True: |
34 |
- os.kill(pid, signal.SIGTERM) |
35 |
- time.sleep(2.0) |
36 |
- |
37 |
if shell: |
38 |
args = cmd |
39 |
else: |
40 |
@@ -71,19 +65,16 @@ class Execute(): |
41 |
if not timed_out: |
42 |
# _rc = None if we had a timeout |
43 |
_rc = proc.returncode |
44 |
- if _rc: |
45 |
- _file.write('EXIT CODE: %d\n' % _rc) |
46 |
- if not failok: |
47 |
- _file.write('SENDING SIGTERM\n') |
48 |
- _file.close() |
49 |
- signalexit() |
50 |
+ _file.write('EXIT CODE: %d\n' % _rc) |
51 |
|
52 |
if timed_out: |
53 |
_file.write('TIMEOUT ERROR: %s\n' % cmd) |
54 |
- if not failok: |
55 |
- _file.write('SENDING SIGTERM\n') |
56 |
- _file.close() |
57 |
- signalexit() |
58 |
+ |
59 |
+ if not failok and ( _rc != 0 or timed_out): |
60 |
+ pid = os.getpid() |
61 |
+ _file.write('SENDING SIGTERM: %s\n' % pid) |
62 |
+ _file.close() |
63 |
+ os.kill(pid, signal.SIGTERM) |
64 |
|
65 |
# Only close a logfile, don't close sys.stderr! |
66 |
if logfile: |
67 |
|
68 |
diff --git a/grs/Interpret.py b/grs/Interpret.py |
69 |
index 3e2c408..5624fd4 100644 |
70 |
--- a/grs/Interpret.py |
71 |
+++ b/grs/Interpret.py |
72 |
@@ -64,12 +64,7 @@ class Interpret(Daemon): |
73 |
if mypid == pid: |
74 |
continue |
75 |
try: |
76 |
- for i in range(10): |
77 |
- os.kill(pid, signal.SIGTERM) |
78 |
- time.sleep(0.2) |
79 |
- while True: |
80 |
- os.kill(pid, signal.SIGKILL) |
81 |
- time.sleep(0.2) |
82 |
+ os.kill(pid, signal.SIGKILL) |
83 |
except ProcessLookupError: |
84 |
pass |
85 |
try: |
86 |
@@ -79,13 +74,6 @@ class Interpret(Daemon): |
87 |
sys.exit(signum + 128) |
88 |
|
89 |
|
90 |
- def signalexit(): |
91 |
- pid = os.getpid() |
92 |
- while True: |
93 |
- os.kill(pid, signal.SIGTERM) |
94 |
- time.sleep(2.0) |
95 |
- |
96 |
- |
97 |
def semantic_action(_line, objs, nargs, func, *args): |
98 |
""" Execute the directive """ |
99 |
err = None |
100 |
@@ -104,7 +92,7 @@ class Interpret(Daemon): |
101 |
_lo.log('Bad command: %s' % _line) |
102 |
_lo.log('Error message: %s' % err) |
103 |
_lo.log('SENDING SIGTERM\n') |
104 |
- signalexit() |
105 |
+ os.kill(os.getpid(), signal.SIGTERM) |
106 |
|
107 |
|
108 |
def stampit(progress): |
109 |
@@ -262,7 +250,7 @@ class Interpret(Daemon): |
110 |
_lo.log('Bad command: %s' % _line) |
111 |
_lo.log('Unknown verb: %s' % verb) |
112 |
_lo.log('SENDING SIGTERM\n') |
113 |
- signalexit() |
114 |
+ os.kill(os.getpid(), signal.SIGTERM) |
115 |
|
116 |
stampit(progress) |