def setup_local_socket(socket_dir, socket_dirs, display_name, clobber, mmap_group, socket_permissions): if sys.platform.startswith("win"): return None, None from xpra.log import Logger log = Logger("network") dotxpra = DotXpra(socket_dir or socket_dirs[0]) try: dotxpra.mksockdir() display_name = normalize_local_display_name(display_name) sockpath = dotxpra.socket_path(display_name) except Exception as e: raise InitException("socket path error: %s" % e) setup_server_socket_path(dotxpra, sockpath, display_name, clobber, wait_for_unknown=5) sock = create_unix_domain_socket(sockpath, mmap_group, socket_permissions) def cleanup_socket(): log.info("removing socket %s", sockpath) try: os.unlink(sockpath) except: pass _cleanups.append(cleanup_socket) return ("unix-domain", sock, sockpath), cleanup_socket
def __init__(self): dotxpra = DotXpra() display = os.environ.get("DISPLAY") from xpra.scripts.config import make_defaults_struct opts = make_defaults_struct() target = dotxpra.socket_path(display) log.info("attempting to connect to socket: %s", target) sock = socket.socket(socket.AF_UNIX) sock.connect(target) conn = SocketConnection(sock, sock.getsockname(), sock.getpeername(), target, "scroll-test") log.info("successfully created our socket connection: %s", conn) self.server = ServerMessenger(conn, opts) self.vscroll_events = maxdeque(1000) self.hscroll_events = maxdeque(1000) browser = WebBrowser() #hook some events: browser.content_tabs.connect("focus-view-title-changed", self.title_changed) vscroll_listeners.append(self.vscroll) hscroll_listeners.append(self.hscroll) #the things we tune: self.quality = -1 self.speed = -1 self.encoding = None self.strict = False
def create_control_socket(self): assert self.socket_dir dotxpra = DotXpra(self.socket_dir) sockpath = dotxpra.socket_path(":proxy-%s" % os.getpid()) state = dotxpra.get_server_state(sockpath) if state in (DotXpra.LIVE, DotXpra.UNKNOWN): log.warn( "You already have a proxy server running at %s, the control socket will not be created!", sockpath) return False try: sock = create_unix_domain_socket(sockpath, None, 0o600) sock.listen(5) except Exception as e: log("create_unix_domain_socket failed for '%s'", sockpath, exc_info=True) log.error("Error: failed to setup control socket '%s':", sockpath) log.error(" %s", e) return False self.control_socket = sock self.control_socket_path = sockpath log.info("proxy instance now also available using unix domain socket:") log.info(" %s", self.control_socket_path) return True
def __init__(self): dotxpra = DotXpra() display = os.environ.get("DISPLAY") from xpra.scripts.config import make_defaults_struct opts = make_defaults_struct() target = dotxpra.socket_path(display) log.info("attempting to connect to socket: %s", target) sock = socket.socket(socket.AF_UNIX) sock.connect(target) conn = SocketConnection(sock, sock.getsockname(), sock.getpeername(), target, "scroll-test") log.info("successfully created our socket connection: %s", conn) self.server = ServerMessenger(conn, opts) self.vscroll_events = deque(maxlen=1000) self.hscroll_events = deque(maxlen=1000) browser = WebBrowser() #hook some events: browser.content_tabs.connect("focus-view-title-changed", self.title_changed) vscroll_listeners.append(self.vscroll) hscroll_listeners.append(self.hscroll) #the things we tune: self.quality = -1 self.speed = -1 self.encoding = None self.strict = False
def client_sock(parser, opts, display_name): if display_name.startswith("ssh:"): sshspec = display_name[len("ssh:"):] if ":" in sshspec: (host, display) = sshspec.split(":", 1) display_args = [":" + display] else: host = sshspec display_args = [] (a, b) = socket.socketpair() if opts.remote_xpra is not None: remote_xpra = opts.remote_xpra.split() else: remote_xpra = ["$HOME/.xpra/run-xpra"] p = subprocess.Popen(["ssh", host, "-e", "none"] + remote_xpra + ["_proxy"] + display_args, stdin=b.fileno(), stdout=b.fileno(), bufsize=0) return a, False elif display_name.startswith(":"): sockdir = DotXpra() sock = socket.socket(socket.AF_UNIX) sock.connect(sockdir.socket_path(display_name)) return sock, True elif display_name.startswith("tcp:"): host_spec = display_name[4:] (host, port) = host_spec.split(":", 1) if host == "": host = "127.0.0.1" sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((host, int(port))) return sock, True else: parser.error("unknown format for display name")
def run_list(parser, opts, extra_args): if extra_args: parser.error("too many arguments for mode") sockdir = DotXpra() results = sockdir.sockets() if not results: sys.stdout.write("No xpra sessions found\n") else: sys.stdout.write("Found the following xpra sessions:\n") for state, display in results: sys.stdout.write("\t%s session at %s" % (state, display)) if state is DotXpra.DEAD: try: os.unlink(sockdir.socket_path(display)) except OSError: pass else: sys.stdout.write(" (cleaned up)") sys.stdout.write("\n")
def run_list(parser, opts, extra_args): assert "gtk" not in sys.modules if extra_args: parser.error("too many arguments for mode") sockdir = DotXpra() results = sockdir.sockets() if not results: sys.stdout.write("No xpra sessions found\n") else: sys.stdout.write("Found the following xpra sessions:\n") for state, display in results: sys.stdout.write("\t%s session at %s" % (state, display)) if state is DotXpra.DEAD: try: os.unlink(sockdir.socket_path(display)) except OSError: pass else: sys.stdout.write(" (cleaned up)") sys.stdout.write("\n")
def create_control_socket(self): assert self.socket_dir dotxpra = DotXpra(self.socket_dir) sockpath = dotxpra.socket_path(":proxy-%s" % os.getpid()) state = dotxpra.get_server_state(sockpath) if state in (DotXpra.LIVE, DotXpra.UNKNOWN): log.warn("You already have a proxy server running at %s, the control socket will not be created!", sockpath) return False try: sock = create_unix_domain_socket(sockpath, None, 0o600) sock.listen(5) except Exception as e: log("create_unix_domain_socket failed for '%s'", sockpath, exc_info=True) log.error("Error: failed to setup control socket '%s':", sockpath) log.error(" %s", e) return False self.control_socket = sock self.control_socket_path = sockpath log.info("proxy instance now also available using unix domain socket:") log.info(" %s", self.control_socket_path) return True
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=cmd) elif display_desc["type"] == "unix-domain": sockdir = DotXpra(display_desc["sockdir"]) sock = socket.socket(socket.AF_UNIX) sockfile = sockdir.socket_path(display_desc["display"]) return _socket_connect(sock, sockfile) elif display_desc["type"] == "tcp": sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tcp_endpoint = (display_desc["host"], display_desc["port"]) return _socket_connect(sock, tcp_endpoint) else: assert False, "unsupported display type in connect" def run_client(parser, opts, extra_args, mode): if mode == "screenshot": if len(extra_args) == 0: parser.error("invalid number of arguments for screenshot mode")
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) elif display_desc["type"] == "unix-domain": sockdir = DotXpra(display_desc["sockdir"]) sock = socket.socket(socket.AF_UNIX) sockfile = sockdir.socket_path(display_desc["display"]) return _socket_connect(sock, sockfile, display_name) elif display_desc["type"] == "tcp": sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tcp_endpoint = (display_desc["host"], display_desc["port"]) return _socket_connect(sock, tcp_endpoint, display_name) else: assert False, "unsupported display type in connect" def run_client(parser, opts, extra_args, mode): if mode=="screenshot": if len(extra_args)==0: parser.error("invalid number of arguments for screenshot mode")