diff --git a/tests/echo.py b/tests/echo.py index b297a52..bd4aaee 100755 --- a/tests/echo.py +++ b/tests/echo.py @@ -34,9 +34,11 @@ class WebSocketEcho(WebSockifyRequestHandler): while True: wlist = [] - if cqueue or c_pend: wlist.append(self.request) + if cqueue or c_pend: + wlist.append(self.request) ins, outs, excepts = select.select(rlist, wlist, [], 1) - if excepts: raise Exception("Socket exception") + if excepts: + raise Exception("Socket exception") if self.request in outs: # Send queued target data to the client @@ -65,7 +67,8 @@ if __name__ == '__main__': (opts, args) = parser.parse_args() try: - if len(args) != 1: raise ValueError + if len(args) != 1: + raise ValueError opts.listen_port = int(args[0]) except ValueError: parser.error("Invalid arguments") diff --git a/tests/echo_client.py b/tests/echo_client.py index 58bc039..ce0c0d2 100755 --- a/tests/echo_client.py +++ b/tests/echo_client.py @@ -31,11 +31,13 @@ def send(msg): except WebSocketWantReadError: msg = '' ins, outs, excepts = select.select([sock], [], []) - if excepts: raise Exception("Socket exception") + if excepts: + raise Exception("Socket exception") except WebSocketWantWriteError: msg = '' ins, outs, excepts = select.select([], [sock], []) - if excepts: raise Exception("Socket exception") + if excepts: + raise Exception("Socket exception") def read(): @@ -44,10 +46,12 @@ def read(): return sock.recvmsg() except WebSocketWantReadError: ins, outs, excepts = select.select([sock], [], []) - if excepts: raise Exception("Socket exception") + if excepts: + raise Exception("Socket exception") except WebSocketWantWriteError: ins, outs, excepts = select.select([], [sock], []) - if excepts: raise Exception("Socket exception") + if excepts: + raise Exception("Socket exception") counter = 1 @@ -59,7 +63,8 @@ while True: while True: ins, outs, excepts = select.select([sock], [], [], 1.0) - if excepts: raise Exception("Socket exception") + if excepts: + raise Exception("Socket exception") if ins == []: break diff --git a/tests/load.py b/tests/load.py index f0c0a7a..14e1f2f 100755 --- a/tests/load.py +++ b/tests/load.py @@ -50,7 +50,8 @@ class WebSocketLoad(WebSockifyRequestHandler): while True: ins, outs, excepts = select.select(socks, socks, socks, 1) - if excepts: raise Exception("Socket exception") + if excepts: + raise Exception("Socket exception") if client in ins: frames, closed = self.recv_frames() @@ -148,10 +149,12 @@ if __name__ == '__main__': (opts, args) = parser.parse_args() try: - if len(args) != 1: raise ValueError + if len(args) != 1: + raise ValueError opts.listen_port = int(args[0]) - if len(args) not in [1, 2]: raise ValueError + if len(args) not in [1, 2]: + raise ValueError opts.listen_port = int(args[0]) if len(args) == 2: opts.delay = int(args[1]) diff --git a/websockify/websocketproxy.py b/websockify/websocketproxy.py index f7eadaf..6e19e72 100644 --- a/websockify/websocketproxy.py +++ b/websockify/websocketproxy.py @@ -201,8 +201,10 @@ Traffic Legend: self.heartbeat = now + self.server.heartbeat self.send_ping() - if tqueue: wlist.append(target) - if cqueue or c_pend: wlist.append(self.request) + if tqueue: + wlist.append(target) + if cqueue or c_pend: + wlist.append(self.request) try: ins, outs, excepts = select.select(rlist, wlist, [], 1) except OSError: @@ -217,7 +219,8 @@ Traffic Legend: else: continue - if excepts: raise Exception("Socket exception") + if excepts: + raise Exception("Socket exception") if self.request in outs: # Send queued target data to the client diff --git a/websockify/websockifyserver.py b/websockify/websockifyserver.py index 542378e..7342b6e 100644 --- a/websockify/websockifyserver.py +++ b/websockify/websockifyserver.py @@ -528,9 +528,11 @@ class WebSockifyServer(): os.setuid(os.getuid()) # relinquish elevations # Double fork to daemonize - if os.fork() > 0: os._exit(0) # Parent exits - os.setsid() # Obtain new process group - if os.fork() > 0: os._exit(0) # Parent exits + if os.fork() > 0: # Parent exits + os._exit(0) + os.setsid() # Obtain new process group + if os.fork() > 0: # Parent exits + os._exit(0) # Signal handling signal.signal(signal.SIGTERM, signal.SIG_IGN) @@ -538,14 +540,16 @@ class WebSockifyServer(): # Close open files maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1] - if maxfd == resource.RLIM_INFINITY: maxfd = 256 + if maxfd == resource.RLIM_INFINITY: + maxfd = 256 for fd in reversed(range(maxfd)): try: if fd not in keepfd: os.close(fd) except OSError: _, exc, _ = sys.exc_info() - if exc.errno != errno.EBADF: raise + if exc.errno != errno.EBADF: + raise # Redirect I/O to /dev/null os.dup2(os.open(os.devnull, os.O_RDWR), sys.stdin.fileno())