xpra icon
Bug tracker and wiki

Ticket #172: 0001-fix-Xorg.N.log-location.patch

File 0001-fix-Xorg.N.log-location.patch, 4.9 KB (added by Benoit Gschwind, 6 years ago)

fix the logfile location

  • src/xpra/scripts/server.py

    From a8a43ff527585825e4eedd3f869699e592b40f3c Mon Sep 17 00:00:00 2001
    From: Benoit Gschwind <gschwind@gnu-log.net>
    Date: Sat, 31 May 2014 13:23:17 +0200
    Subject: [PATCH] fix Xorg.N.log location
    
    ---
     src/xpra/scripts/server.py | 41 ++++++++++++++++++++++++++++++-----------
     1 file changed, 30 insertions(+), 11 deletions(-)
    
    diff --git a/src/xpra/scripts/server.py b/src/xpra/scripts/server.py
    index 4450802..6693bd3 100644
    a b import socket 
    1919import getpass
    2020import select
    2121import re
     22from datetime import datetime
    2223
    2324from xpra.scripts.main import TCP_NODELAY
    2425from xpra.dotxpra import DotXpra, ServerSockInUse
    def start_Xvfb(xvfb_str, display_name): 
    482483    subs = {"XAUTHORITY"    : xauthority,
    483484            "USER"          : os.environ.get("USER", "unknown-user"),
    484485            "HOME"          : os.environ.get("HOME", os.getcwd()) }
    485     if display_name:
    486         subs["DISPLAY"] = display_name
     486
     487       
    487488    for var,value in subs.items():
    488489        xvfb_str = xvfb_str.replace("$%s" % var, value)
    489490        xvfb_str = xvfb_str.replace("${%s}" % var, value)
    def start_Xvfb(xvfb_str, display_name): 
    494495            os.setsid()
    495496
    496497    xvfb_cmd = xvfb_str.split()
     498
     499    if '-logfile' in xvfb_cmd:
     500        xorg_log_file = xvfb_cmd[xvfb_cmd.index('-logfile')+1]
     501        for i in  range(len(xvfb_cmd)):
     502            xvfb_cmd[i] = re.sub("\$(DISPLAY|\{DISPLAY\})", display_name, xvfb_cmd[i])
     503        print xorg_log_file
     504    else:
     505        xorg_log_file = None
     506
     507       
    497508    xvfb_executable = xvfb_cmd[0]
    498509    # TODO: if Xvfb does not support -displayfd -> Error
    499     if not display_name:
     510    if display_name[0] == 'S':
    500511        # allocate display automaticaly
    501512        r_pipe, w_pipe = os.pipe()
    502513        xvfb_cmd += ["-displayfd", str(w_pipe)]
    503         xvfb_cmd[0] = "%s-for-Xpra-%s" % (xvfb_executable, str(os.getpid()))
     514        xvfb_cmd[0] = "%s-for-Xpra-%s" % (xvfb_executable, display_name)
    504515        xvfb = subprocess.Popen(xvfb_cmd, executable=xvfb_executable, close_fds=False,
    505516                                stdin=subprocess.PIPE, preexec_fn=setsid)
     517        start = datetime.now()
    506518        # Read the display number from the pipe we gave to Xvfb
    507519        buf = ""
    508520        # Wait for 4.0 seconds each time, at most 3 times:
    509         for _ in range(3):
    510             r, _, _ = select.select([r_pipe], [], [], 4.0)
     521        while (datetime.now() - start).total_seconds() < 10.0:
     522            r, _, _ = select.select([r_pipe], [], [], (datetime.now() - start).total_seconds())
    511523            if r_pipe in r:
    512524                buf += os.read(r_pipe, 256)
    513525                if buf[-1] == '\n':
    def start_Xvfb(xvfb_str, display_name): 
    516528            raise OSError("%s did not provide a display number using -displayfd" % xvfb_executable)
    517529        if not re.match("^\d+$", buf):
    518530            raise OSError("%s provided an invalid display number: %s" % (xvfb_executable, buf))
    519         display_name = ":" + buf[:-1]
    520         sys.stdout.write("Using vfb provided display: %s\n" % display_name)
     531        new_display_name = ":" + buf[:-1]
     532        sys.stdout.write("Using vfb provided display: %s\n" % new_display_name)
     533        if xorg_log_file != None:
     534            f0 = re.sub("\$(DISPLAY|\{DISPLAY\})", display_name, xorg_log_file)
     535            f1 = re.sub("\$(DISPLAY|\{DISPLAY\})", new_display_name, xorg_log_file)
     536            print f0, f1
     537            if f0 != f1:
     538                os.rename(f0, f1)
     539        display_name = new_display_name
    521540    else:
    522541        # use display specified
    523542        xvfb_cmd[0] = "%s-for-Xpra-%s" % (xvfb_executable, display_name)
    def run_server(parser, opts, mode, xpra_file, extra_args): 
    678697            if not opts.displayfd:
    679698                parser.error("displayfd support is not enabled, you must specify the display to use")
    680699            # We will try to find one automaticaly
    681             display_name = None
     700            display_name = 'S' + str(os.getpid())
    682701
    683702    if not shadowing and not proxying and opts.exit_with_children and not opts.start_child:
    684703        sys.stderr.write("--exit-with-children specified without any children to spawn; exiting immediately")
    def run_server(parser, opts, mode, xpra_file, extra_args): 
    721740    log = Logger("server")
    722741
    723742    # Do this after writing out the shell script:
    724     if display_name:
     743    if display_name[0] != 'S':
    725744        os.environ["DISPLAY"] = display_name
    726745    sanitize_env()
    727746
    def run_server(parser, opts, mode, xpra_file, extra_args): 
    740759        log_filename1 = select_log_file(dotxpra, opts.log_file, display_name)
    741760        if log_filename0 != log_filename1:
    742761            os.rename(log_filename0, log_filename1)
    743             stderr.write("Actual log file name is now: %s", log_filename1)
     762            stderr.write("Actual log file name is now: %s" % log_filename1)
    744763        stdout.close()
    745764        stderr.close()
    746765    if display_name: