xpra icon
Bug tracker and wiki

Ticket #172: 0002-make-xpra-backward-compatible.patch

File 0002-make-xpra-backward-compatible.patch, 6.4 KB (added by Benoit Gschwind, 6 years ago)

make xpra backward compatible

  • src/xpra/dotxpra.py

    From 029b610661d283a8c390d6a6acfaf7d866897fe5 Mon Sep 17 00:00:00 2001
    From: Benoit Gschwind <gschwind@gnu-log.net>
    Date: Sat, 24 May 2014 15:23:01 +0200
    Subject: [PATCH 2/2] make xpra backward compatible
    
     * new dynamique DISPLAY session are S9999
     * old are keep to :9999
    ---
     src/xpra/dotxpra.py        |  2 +-
     src/xpra/scripts/main.py   | 25 ++++++++++-----------
     src/xpra/scripts/server.py | 54 +++++++++++++++++++++++++++++-----------------
     3 files changed, 48 insertions(+), 33 deletions(-)
    
    diff --git a/src/xpra/dotxpra.py b/src/xpra/dotxpra.py
    index ec2cae5..9e57235 100644
    a b class DotXpra(object): 
    4545        return self._confdir
    4646
    4747    def normalize_local_session_id(self, local_session_string):
    48         assert re.match("^[1234567890]+$", local_session_string)
     48        assert re.match("^S\d+$", local_session_string) or re.match("^:\d+(\.\d+)?$", local_session_string)
    4949        return local_session_string
    5050
    5151    def norm_make_path(self, name, dirpath):
  • src/xpra/scripts/main.py

    diff --git a/src/xpra/scripts/main.py b/src/xpra/scripts/main.py
    index 0056e3d..28da6ba 100644
    a b def parse_session_string(error_cb, opts, session_string): 
    652652            #ssh:HOST:ID or ssh/HOST/ID
    653653            host = separator.join(parts[1:-1])
    654654            session_id = parts[-1]
     655            if session_id[0] != 'S':
     656                session_id = ":"+session_id
    655657            desc["session_id"] = session_id
    656658            opts.session_id = session_id
    657659            desc["display_as_args"] = [session_id]
    def parse_session_string(error_cb, opts, session_string): 
    732734        #display (optional):
    733735        if len(parts)==4:
    734736            session_id = parts[3]
    735             if session_id:
    736                 try:
    737                     v = int(session_id)
    738                     session_id = "%s" % v
    739                 except:
    740                     pass
    741                 desc["session_id"] = session_id
    742                 opts.session_id = session_id
     737            if session_id[0] != 'S':
     738                session_id = ":"+session_id   
     739            desc["session_id"] = session_id
     740            opts.session_id = session_id
     741        else:
     742            desc["session_id"] = None
    743743        #port:
    744744        port = parts[2]
    745745        try:
    def parse_session_string(error_cb, opts, session_string): 
    760760            host = "127.0.0.1"
    761761        desc["host"] = host
    762762        return desc
    763     elif re.match('^[1234567890]+$', session_string):
     763    elif re.match("^S\d+$", session_string) or re.match("^:\d+(\.\d+)?$", session_string):
    764764        desc["type"] = "unix-domain"
    765765        desc["local"] = True
    766         desc["session_id"] = session_string
    767         opts.session_id = session_string
     766        session_id = session_string
     767        desc["session_id"] = session_id
     768        opts.session_id = session_id
     769
    768770        desc["socket_dir"] = osexpand(opts.socket_dir or get_default_socket_dir(), opts.username)
    769771        return desc
    770772    else:
    def _socket_connect(sock, endpoint, description, dtype): 
    798800
    799801def connect_or_fail(session_desc):
    800802    try:
    801         print "try connection to", session_desc
    802803        return connect_to(session_desc)
    803804    except Exception, e:
    804805        sys.exit("connection failed: %s" % e)
  • src/xpra/scripts/server.py

    diff --git a/src/xpra/scripts/server.py b/src/xpra/scripts/server.py
    index acbb0ca..d06e64c 100644
    a b def start_Xvfb(xvfb_str, session_id): 
    478478        if os.name=="posix":
    479479            os.setsid()
    480480
    481     # allocate display automaticaly
    482     r_pipe, w_pipe = os.pipe()
    483     xvfb_cmd = xvfb_str.split()+["-displayfd", str(w_pipe)]
    484     xvfb_executable = xvfb_cmd[0]
    485     xvfb_cmd[0] = "%s-for-Xpra-%s" % (xvfb_executable, str(session_id))
    486     xvfb = subprocess.Popen(xvfb_cmd, executable=xvfb_executable, close_fds=False,
    487                             stdin=subprocess.PIPE, preexec_fn=setsid)
    488     # Wait to get display number from Xvfb
    489     buf = ""
    490     while True:
    491      select.select([r_pipe], [], [])
    492      buf += os.read(r_pipe, 256)
    493      # TODO: add time out to avoid infite blocking.
    494      if buf[-1] == '\n':
    495       break
    496     display_name = ":" + buf[:-1]
    497     sys.stdout.write("Dynamicaly openned display = %s\n" % display_name)
     481    if session_id[0] == 'S':
     482        # allocate display automaticaly
     483        r_pipe, w_pipe = os.pipe()
     484        xvfb_cmd = xvfb_str.split()+["-displayfd", str(w_pipe)]
     485        xvfb_executable = xvfb_cmd[0]
     486        xvfb_cmd[0] = "%s-for-Xpra-%s" % (xvfb_executable, session_id)
     487        xvfb = subprocess.Popen(xvfb_cmd, executable=xvfb_executable, close_fds=False,
     488                                stdin=subprocess.PIPE, preexec_fn=setsid)
     489        # Wait to get display number from Xvfb
     490        buf = ""
     491        while True:
     492         select.select([r_pipe], [], [])
     493         buf += os.read(r_pipe, 256)
     494         # TODO: add time out to avoid infite blocking.
     495         if buf[-1] == '\n':
     496          break
     497        display_name = ":" + buf[:-1]
     498        sys.stdout.write("Dynamicaly openned display = %s\n" % display_name)
     499    elif session_id[0] == ':':
     500        # allocate display automaticaly
     501        xvfb_cmd = xvfb_str.split()+[session_id]
     502        xvfb_executable = xvfb_cmd[0]
     503        xvfb_cmd[0] = "%s-for-Xpra-%s" % (xvfb_executable, session_id)
     504        xvfb = subprocess.Popen(xvfb_cmd, executable=xvfb_executable, close_fds=True,
     505                                stdin=subprocess.PIPE, preexec_fn=setsid)
     506        display_name = session_id
     507
     508
    498509    from xpra.os_util import get_hex_uuid
    499510    xauth_cmd = ["xauth", "add", display_name, "MIT-MAGIC-COOKIE-1", get_hex_uuid()]
    500511    try:
    def run_server(parser, opts, mode, xpra_file, extra_args): 
    641652        from xpra.scripts.main import guess_X11_display
    642653        display_name = guess_X11_display()
    643654    else:
    644         if len(extra_args) > 0:
    645             parser.error("do not need extra arguments")
     655        if len(extra_args) > 1:
     656            parser.error("too much extra arguments")
    646657        display_name = None
    647         session_id = str(os.getpid())
     658        if len(extra_args) == 1:
     659            session_id = extra_args[0]
     660        else:
     661            session_id = "S" + str(os.getpid())
    648662
    649663    if not shadowing and not proxying and opts.exit_with_children and not opts.start_child:
    650664        sys.stderr.write("--exit-with-children specified without any children to spawn; exiting immediately")