def start_dbus(dbus_launch): if not dbus_launch or dbus_launch.lower() in FALSE_OPTIONS: return 0, {} try: def preexec(): assert POSIX os.setsid() close_fds() proc = subprocess.Popen(dbus_launch, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True, preexec_fn=preexec) out, _ = proc.communicate() assert proc.poll() == 0, "exit code is %s" % proc.poll() #parse and add to global env: dbus_env = {} for l in out.splitlines(): parts = l.split("=", 1) if len(parts) != 2: continue k, v = parts if v.startswith("'") and v.endswith("';"): v = v[1:-2] dbus_env[k] = v dbus_pid = int(dbus_env.get("DBUS_SESSION_BUS_PID", 0)) return dbus_pid, dbus_env except Exception as e: error("dbus-launch failed to start using command '%s':\n" % dbus_launch) error(" %s\n" % e) return 0, {}
def save_dbus_env(env): #DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-B8CDeWmam9,guid=b77f682bd8b57a5cc02f870556cbe9e9 #DBUS_SESSION_BUS_PID=11406 #DBUS_SESSION_BUS_WINDOWID=50331649 def u(s): try: return s.decode("latin1") except: return str(s) for n, conv, save in (("ADDRESS", u, _save_str), ("PID", int, _save_int), ("WINDOW_ID", int, _save_int)): k = "DBUS_SESSION_BUS_%s" % n v = env.get(k) if v is None: continue try: tv = conv(v) save(k, tv) except Exception as e: get_util_logger().debug("save_dbus_env(%s)", env, exc_info=True) error( "failed to save dbus environment variable '%s' with value '%s':\n" % (k, v)) error(" %s\n" % e)
def get_dbus_env(): env = {} for n, load in (("ADDRESS", _get_str), ("PID", _get_int), ("WINDOW_ID", _get_int)): k = "DBUS_SESSION_BUS_%s" % n try: v = load(k) if v: env[k] = str(v) except Exception as e: error("failed to load dbus environment variable '%s':\n" % k) error(" %s\n" % e) return env
def save_dbus_env(env): #DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-B8CDeWmam9,guid=b77f682bd8b57a5cc02f870556cbe9e9 #DBUS_SESSION_BUS_PID=11406 #DBUS_SESSION_BUS_WINDOWID=50331649 for n, conv, save in (("ADDRESS", str, _save_str), ("PID", int, _save_int), ("WINDOW_ID", int, _save_int)): k = "DBUS_SESSION_BUS_%s" % n v = env.get(k) if v is None: continue try: tv = conv(v) save(k, tv) except Exception as e: error( "failed to save dbus environment variable '%s' with value '%s':\n" % (k, v)) error(" %s\n" % e)
def command_error(message): from xpra.scripts.main import error error(message)