From 8041cab5271d4b67b4936e1786a3834021a16af2 Mon Sep 17 00:00:00 2001 From: Alon Bar-Lev Date: Wed, 5 Jun 2013 15:16:46 +0300 Subject: [PATCH] WebSocketProxy: support non path target_cfg The WebSocketProxy class is usable for creating derived applications with different logic, especially for the target validation. Current code assumes that target is a path while in other implementation it can be object that is loaded at initialization. This change moves the conversion to absolute path into main function, so that the WebSocketProxy class will not make that assumption. Signed-off-by: Alon Bar-Lev --- utils/websockify | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utils/websockify b/utils/websockify index 1154d925..a1e9133f 100755 --- a/utils/websockify +++ b/utils/websockify @@ -80,9 +80,6 @@ Traffic Legend: "REBIND_OLD_PORT": str(kwargs['listen_port']), "REBIND_NEW_PORT": str(self.target_port)}) - if self.target_cfg: - self.target_cfg = os.path.abspath(self.target_cfg) - websocket.WebSocketServer.__init__(self, *args, **kwargs) def run_wrap_cmd(self): @@ -385,6 +382,10 @@ def websockify_init(): try: opts.target_port = int(opts.target_port) except: parser.error("Error parsing target port") + # Transform to absolute path as daemon may chdir + if opts.target_cfg: + opts.target_cfg = os.path.abspath(opts.target_cfg) + # Create and start the WebSockets proxy server = WebSocketProxy(**opts.__dict__) server.start_server()