Commit 215ae8e5 authored by Joel Martin's avatar Joel Martin

Better reaper, catch occasional bad WS header line.

Call waitpid in loop to catch SIGCHLD signals that happen while
handling the original SIGCHLD signal.

Pulled from websockify.
parent ec2b6140
...@@ -147,7 +147,10 @@ Connection: Upgrade\r ...@@ -147,7 +147,10 @@ Connection: Upgrade\r
ret['path'] = req_lines[0].split(" ")[1] ret['path'] = req_lines[0].split(" ")[1]
for line in req_lines[1:]: for line in req_lines[1:]:
if line == "": break if line == "": break
try:
var, val = line.split(": ") var, val = line.split(": ")
except:
raise Exception("Invalid handshake header: %s" % line)
ret[var] = val ret[var] = val
if req_lines[-2] == "": if req_lines[-2] == "":
...@@ -315,12 +318,17 @@ Connection: Upgrade\r ...@@ -315,12 +318,17 @@ Connection: Upgrade\r
#self.vmsg("Running poll()") #self.vmsg("Running poll()")
pass pass
def top_SIGCHLD(self, sig, stack): def top_SIGCHLD(self, sig, stack):
# Reap zombies after calling child SIGCHLD handler # Reap zombies after calling child SIGCHLD handler
self.do_SIGCHLD(sig, stack) self.do_SIGCHLD(sig, stack)
self.vmsg("Got SIGCHLD, reaping zombies") self.vmsg("Got SIGCHLD, reaping zombies")
os.waitpid(-1, os.WNOHANG) try:
result = os.waitpid(-1, os.WNOHANG)
while result[0]:
self.vmsg("Reaped child process %s" % result[0])
result = os.waitpid(-1, os.WNOHANG)
except (OSError):
pass
def do_SIGCHLD(self, sig, stack): def do_SIGCHLD(self, sig, stack):
pass pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment