Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* use "--env=KEY=VALUE" command line argument to pass the proxy start UUID to the server, as this will also work for osx shadow servers started via the launchctl agent whereas environment variable do not get passed through
* try harder to decode the process output
* use a "nodock" subprocess for probing the new server using "xpra info" so this won't show up in the dock

git-svn-id: https://xpra.org/svn/Xpra/trunk@14942 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 1, 2017
1 parent 5a98ec2 commit 3676764
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/xpra/platform/darwin/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def do_get_sshpass_command():
return None


def do_get_sound_command():
def do_get_nodock_command():
#try to use the subapp:
from xpra.platform.paths import get_app_dir
base = get_app_dir()
Expand All @@ -156,3 +156,6 @@ def do_get_sound_command():
if not os.path.exists(helper):
helper = os.path.join(base, "Helpers", "Xpra")
return [helper]

def do_get_sound_command():
return do_get_nodock_command()
12 changes: 12 additions & 0 deletions src/xpra/platform/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ def do_get_xpra_command():
return ["xpra"]


def get_nodock_command():
envvalue = os.environ.get("XPRA_NODOCK_COMMAND")
if envvalue:
import shlex
return shlex.split(envvalue)
return do_get_nodock_command()
def do_get_nodock_command():
return get_xpra_command()


def get_sound_command():
envvalue = os.environ.get("XPRA_SOUND_COMMAND")
if envvalue:
Expand All @@ -230,6 +240,7 @@ def do_get_sound_command():
"do_get_sshpass_command",
"do_get_xpra_command",
"do_get_sound_command",
"do_get_nodock_command",
"do_get_install_prefix",
"do_get_default_conf_dirs",
"do_get_system_conf_dirs",
Expand All @@ -253,6 +264,7 @@ def get_info():
"resources" : get_resources_dir(),
"icons" : get_icon_dir(),
"home" : os.path.expanduser("~"),
"nodock_command" : get_nodock_command(),
"sound_command" : get_sound_command(),
"sshpass_command" : get_sshpass_command(),
}
Expand Down
28 changes: 18 additions & 10 deletions src/xpra/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2353,16 +2353,9 @@ def start_server_subprocess(script_file, args, mode, defaults,
for x in socket_dirs:
cmd.append("--socket-dirs=%s" % (x or ""))
#add a unique uuid to the server env:
server_env = os.environ.copy()
from xpra.os_util import get_hex_uuid
new_server_uuid = get_hex_uuid()
server_env["XPRA_PROXY_START_UUID"] = new_server_uuid
if username:
server_env.update({
"USER" : username,
"USERNAME" : username,
"HOME" : home or os.path.join("/home", username),
})
cmd.append("--env=XPRA_PROXY_START_UUID=%s" % new_server_uuid)
if mode=="shadow" and OSX:
#launch the shadow server via launchctl so it will have GUI access:
LAUNCH_AGENT = "org.xpra.Agent"
Expand Down Expand Up @@ -2395,13 +2388,21 @@ def preexec():
if uid!=0 or gid!=0:
setuidgid(uid, gid)
cmd.append("--systemd-run=no")
server_env = os.environ.copy()
if username:
server_env.update({
"USER" : username,
"USERNAME" : username,
"HOME" : home or os.path.join("/home", username),
})
proc = Popen(cmd, shell=False, close_fds=True, env=server_env, preexec_fn=preexec)
socket_path = identify_new_socket(proc, dotxpra, existing_sockets, matching_display, new_server_uuid, uid)
return proc, socket_path

def identify_new_socket(proc, dotxpra, existing_sockets, matching_display, new_server_uuid, matching_uid=0):
#wait until the new socket appears:
start = time.time()
from xpra.platform.paths import get_nodock_command
while time.time()-start<15 and (proc is None or proc.poll() in (None, 0)):
sockets = set(dotxpra.socket_paths(check_uid=matching_uid, matching_state=dotxpra.LIVE, matching_display=matching_display))
new_sockets = list(sockets-existing_sockets)
Expand All @@ -2410,11 +2411,18 @@ def identify_new_socket(proc, dotxpra, existing_sockets, matching_display, new_s
try:
#we must use a subprocess to avoid messing things up - yuk
import subprocess
cmd = [sys.argv[0], "info", "socket:%s" % socket_path]
cmd = [get_nodock_command(), "info", "socket:%s" % socket_path]
p = subprocess.Popen(cmd, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, _ = p.communicate()
if p.returncode==0:
out = stdout.decode('utf-8')
try:
out = stdout.decode('utf-8')
except:
try:
out = stdout.decode()
except:
from xpra.os_util import bytestostr
out = bytestostr(stdout)
PREFIX = "env.XPRA_PROXY_START_UUID="
for line in out.splitlines():
if line.startswith(PREFIX):
Expand Down

0 comments on commit 3676764

Please sign in to comment.