def run_proxy(parser, opts, extra_args): from xpra.proxy import XpraProxy assert "gtk" not in sys.modules server_conn = connect_or_fail(pick_display(parser, opts, extra_args)) app = XpraProxy(TwoFileConnection(sys.stdout, sys.stdin), server_conn) app.run() return 0
def connect_or_fail(display_desc): display_name = display_desc["display_name"] if display_desc["type"] == "ssh": cmd = (display_desc["full_remote_xpra"] + ["_proxy"] + display_desc["display_as_args"]) try: def setsid(): #run in a new session if os.name == "posix": os.setsid() child = Popen(cmd, stdin=PIPE, stdout=PIPE, preexec_fn=setsid) except OSError, e: sys.exit("Error running ssh program '%s': %s" % (cmd[0], e)) def abort_test(action): """ if ssh dies, we don't need to try to read/write from its sockets """ e = child.poll() if e is not None: error_message = "cannot %s using %s: the SSH process has terminated with exit code=%s" % ( action, display_desc["full_ssh"], e) print(error_message) from wimpiggy.util import gtk_main_quit_really gtk_main_quit_really() raise IOError(error_message) return TwoFileConnection(child.stdin, child.stdout, abort_test, target=display_name)
def run_proxy(parser, opts, script_file, args, start_server=False): from xpra.proxy import XpraProxy assert "gtk" not in sys.modules if start_server: assert len(args) == 1 display_name = args[0] #we must use a subprocess to avoid messing things up - yuk cmd = [script_file, "start"] + args if opts.start_child and len(opts.start_child) > 0: for x in opts.start_child: cmd.append("--start-child=%s" % x) if opts.exit_with_children: cmd.append("--exit-with-children") def setsid(): os.setsid() Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, preexec_fn=setsid) dotxpra = DotXpra() start = time.time() while dotxpra.server_state(display_name, 1) != DotXpra.LIVE: if time.time() - start > 5: warn("server failed to start after %.1f seconds - sorry!" % (time.time() - start)) return time.sleep(0.10) server_conn = connect_or_fail(pick_display(parser, opts, args)) app = XpraProxy( TwoFileConnection(sys.stdout, sys.stdin, info="stdin/stdout"), server_conn) signal.signal(signal.SIGINT, app.quit) signal.signal(signal.SIGTERM, app.quit) app.run() return 0
def run_proxy(parser, opts, extra_args): from xpra.proxy import XpraProxy assert "gtk" not in sys.modules server_conn = connect_or_fail(pick_display(parser, opts, extra_args)) app = XpraProxy(TwoFileConnection(sys.stdout, sys.stdin, info="stdin/stdout"), server_conn) signal.signal(signal.SIGINT, app.quit) signal.signal(signal.SIGTERM, app.quit) app.run() return 0
try: if child.poll() is None: #only supported on win32 since Python 2.7 if hasattr(child, "terminate"): child.terminate() elif hasattr(os, "kill"): os.kill(child.pid, signal.SIGTERM) else: raise Exception( "cannot find function to kill subprocess") except Exception, e: print("error trying to stop ssh tunnel process: %s" % e) return TwoFileConnection(child.stdin, child.stdout, abort_test, target=display_name, info="SSH", close_cb=stop_tunnel) elif dtype == "unix-domain": sockdir = DotXpra(display_desc["socket_dir"]) sock = socket.socket(socket.AF_UNIX) sock.settimeout(5) sockfile = sockdir.socket_path(display_desc["display"]) return _socket_connect(sock, sockfile, display_name) elif dtype == "tcp": sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(10) tcp_endpoint = (display_desc["host"], display_desc["port"]) return _socket_connect(sock, tcp_endpoint, display_name)