From ec2b614037aec641acd5bcce3c1b6d67182534eb Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Mon, 31 Jan 2011 12:13:30 -0600 Subject: [PATCH] Pull websockify: zombie reap, ignore unready clients. --- utils/websocket.py | 20 ++++++++++++++++---- utils/websockify | 5 ++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/utils/websocket.py b/utils/websocket.py index 2bad1588..cfda8706 100755 --- a/utils/websocket.py +++ b/utils/websocket.py @@ -213,7 +213,11 @@ Connection: Upgrade\r stype = "" - # Peek, but don't read the data + ready = select.select([sock], [], [], 3)[0] + if not ready: + raise self.EClose("ignoring socket not ready") + # Peek, but do not read the data so that we have a opportunity + # to SSL wrap the socket first handshake = sock.recv(1024, socket.MSG_PEEK) #self.msg("Handshake [%s]" % repr(handshake)) @@ -308,10 +312,18 @@ Connection: Upgrade\r def poll(self): """ Run periodically while waiting for connections. """ - self.msg("Running poll()") + #self.vmsg("Running poll()") + pass + + + def top_SIGCHLD(self, sig, stack): + # Reap zombies after calling child SIGCHLD handler + self.do_SIGCHLD(sig, stack) + self.vmsg("Got SIGCHLD, reaping zombies") + os.waitpid(-1, os.WNOHANG) def do_SIGCHLD(self, sig, stack): - self.vmsg("Got SIGCHLD, ignoring") + pass def do_SIGINT(self, sig, stack): self.msg("Got SIGINT, exiting") @@ -340,7 +352,7 @@ Connection: Upgrade\r self.started() # Some things need to happen after daemonizing # Reep zombies - signal.signal(signal.SIGCHLD, self.do_SIGCHLD) + signal.signal(signal.SIGCHLD, self.top_SIGCHLD) signal.signal(signal.SIGINT, self.do_SIGINT) while True: diff --git a/utils/websockify b/utils/websockify index fed4c042..e9ef5b3d 100755 --- a/utils/websockify +++ b/utils/websockify @@ -160,7 +160,10 @@ Traffic Legend: try: self.do_proxy(client, tsock) except: - if tsock: tsock.close() + if tsock: + tsock.close() + self.vmsg("%s:%s: Target closed" %( + self.target_host, self.target_port)) if self.rec: self.rec.write("'EOF']\n") self.rec.close()