def create_control_socket(self): assert self.socket_dir def stop(msg): self.stop(None, "cannot create the proxy control socket: %s" % msg) username = get_username_for_uid(self.uid) dotxpra = DotXpra(self.socket_dir, actual_username=username, uid=self.uid, gid=self.gid) sockname = ":proxy-%s" % os.getpid() sockpath = dotxpra.socket_path(sockname) log("%s.socket_path(%s)=%s", dotxpra, sockname, sockpath) state = dotxpra.get_server_state(sockpath) log( "create_control_socket: socket path='%s', uid=%i, gid=%i, state=%s", sockpath, getuid(), getgid(), state) if state in (DotXpra.LIVE, DotXpra.UNKNOWN, DotXpra.INACCESSIBLE): log.error("Error: you already have a proxy server running at '%s'", sockpath) log.error(" the control socket will not be created") stop("socket already exists") return False d = os.path.dirname(sockpath) try: dotxpra.mksockdir(d, SOCKET_DIR_MODE) except Exception as e: log.warn("Warning: failed to create socket directory '%s'", d) log.warn(" %s", e) try: sock, self.control_socket_cleanup = create_unix_domain_socket( sockpath, 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) handle_socket_error(sockpath, 0o600, e) stop(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 main(): print("main()") import gtk import signal from xpra.net.socket_util import create_unix_domain_socket from xpra.x11.vfb_util import start_Xvfb, check_xvfb_process from xpra.scripts.parsing import parse_cmdline from xpra.scripts.main import configure_logging from xpra.platform.dotxpra import DotXpra script_file = sys.argv[0] print("main() script_file=%s" % script_file) cmdline = sys.argv print("main() cmdline=%s" % cmdline) parser, opts, args, mode = parse_cmdline(cmdline) print("main() parser=%s" % parser) print("main() options=%s" % opts) print("main() mode=%s" % mode) display_name = args.pop(0) print("main() display=%s" % display_name) assert mode=="start", "only start mode is supported by this test server" configure_logging(opts, mode) dotxpra = DotXpra(opts.socket_dir) sockpath = dotxpra.socket_path(display_name) socket, cleanup_socket = create_unix_domain_socket(sockpath) sockets = [socket] xvfb = start_Xvfb(opts.xvfb, display_name) assert check_xvfb_process(xvfb), "xvfb error" from xpra.x11.bindings import posix_display_source #@UnusedImport from xpra.x11.bindings.window_bindings import X11WindowBindings #@UnresolvedImport X11Window = X11WindowBindings() assert X11Window try: app = UnrespondingServer() app.init(opts) app.init_sockets(sockets) register_os_signals(app.signal_quit) signal.signal(signal.SIGINT, app.signal_quit) return app.run() finally: for display in gtk.gdk.display_manager_get().list_displays(): display.close() xvfb.terminate() cleanup_socket()