xpra icon
Bug tracker and wiki

Ticket #88: share-mmap.patch

File share-mmap.patch, 9.6 KB (added by Antoine Martin, 9 years ago)

original patch from violetse

  • trunk/src/xpra/client.py

     
    434434                import tempfile
    435435                import uuid
    436436                import ctypes
    437                 from stat import S_IRUSR,S_IWUSR
     437                from stat import S_IRUSR,S_IWUSR,S_IRGRP,S_IWGRP
    438438                mmap_dir = os.getenv("TMPDIR", "/tmp")
    439439                if not os.path.exists(mmap_dir):
    440440                    raise Exception("TMPDIR %s does not exist!" % mmap_dir)
     
    442442                #keep a reference to it so it does not disappear!
    443443                self._mmap_temp_file = temp
    444444                self.mmap_file = temp.name
    445                 #ensure that the permissions are strict:
    446                 os.chmod(self.mmap_file, S_IRUSR|S_IWUSR)
     445                #ensure that the permissions are strict or set mmap-group option:
     446                if opts.mmap_group:
     447                    s = os.stat(opts.sockfile)
     448                    os.chown(self.mmap_file, -1, s.st_uid)
     449                    os.chmod(self.mmap_file, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
     450                else:
     451                    os.chmod(self.mmap_file, S_IRUSR|S_IWUSR)
    447452                self.mmap_size = max(4096, mmap.PAGESIZE)*32*1024   #generally 128MB
    448453                fd = temp.file.fileno()
    449454                log("using mmap file %s, fd=%s, size=%s", self.mmap_file, fd, self.mmap_size)
  • trunk/src/xpra/dotxpra.py

     
    1515    pass
    1616
    1717class DotXpra(object):
    18     def __init__(self, dir=None):
     18    def __init__(self, sockdir=None, logdir=None ):
    1919        assert XPRA_LOCAL_SERVERS_SUPPORTED
    20         if dir is None:
    21             dir = os.path.expanduser("~/.xpra")
    22         self._dir = dir
    23         if not os.path.exists(self._dir):
    24             os.mkdir(dir, 0700)
     20        if logdir is None:
     21            logdir = os.path.expanduser("~/.xpra")
     22        self._logdir = logdir
     23        if sockdir is None:
     24           #sockdir = os.path.expanduser("/tmp/")
     25            sockdir = os.path.expanduser("~/.xpra")
     26        self._sockdir = sockdir
     27        if not os.path.exists(self._logdir):
     28            os.mkdir(logdir, 0700)
    2529        self._prefix = "%s-" % (socket.gethostname(),)
    2630
    27     def dir(self):
    28         return self._dir
     31    def logdir(self):
     32        return self._logdir
    2933
    3034    def _normalize_local_display_name(self, local_display_name):
    3135        if not local_display_name.startswith(":"):
     
    3741            assert char in "0123456789"
    3842        return local_display_name
    3943
    40     def socket_path(self, local_display_name):
     44    def make_path(self, local_display_name, dirpath ):
    4145        local_display_name = self._normalize_local_display_name(local_display_name)
    42         return os.path.join(self._dir, self._prefix + local_display_name[1:])
     46        return os.path.join( dirpath , self._prefix + local_display_name[1:])
    4347
     48    def socket_path(self, local_display_name):
     49        return self.make_path(local_display_name, self._sockdir)
     50
     51    def log_path(self, local_display_name):
     52        return self.make_path(local_display_name, self._logdir)
     53
    4454    LIVE = "LIVE"
    4555    DEAD = "DEAD"
    4656    UNKNOWN = "UNKNOWN"
     
    7484
    7585    def sockets(self):
    7686        results = []
    77         base = os.path.join(self._dir, self._prefix)
     87        base = os.path.join(self._sockdir, self._prefix)
    7888        potential_sockets = glob.glob(base + "*")
    7989        for path in potential_sockets:
    8090            if stat.S_ISSOCK(os.stat(path).st_mode):
  • trunk/src/xpra/scripts/main.py

     
    163163    parser.add_option("--ssh", action="store",
    164164                      dest="ssh", default=DEFAULT_SSH_CMD, metavar="CMD",
    165165                      help="How to run ssh (default: '%default')")
     166    parser.add_option("--socket-dir", action="store",
     167                      dest="sockdir", default=None, metavar="CMD",
     168                      help="Directory to place socket file in (default: '%default')")
     169    parser.add_option("--mmap-group", action="store_true",
     170                      dest="mmap_group", default=False,
     171                      help="Set the group permission on the mmap file the same as the owner of the socket file when creating the mmap file with the client  (default: '%default')")
    166172    parser.add_option("--remote-xpra", action="store",
    167173                      dest="remote_xpra", default=".xpra/run-xpra",
    168174                      metavar="CMD",
     
    263269            "type": "unix-domain",
    264270            "local": True,
    265271            "display": display_name,
     272            "sockdir": opts.sockdir,
    266273            }
    267274        return desc
    268275    elif display_name.startswith("tcp:"):
     
    284291        if not XPRA_LOCAL_SERVERS_SUPPORTED:
    285292            parser.error("need to specify a display")
    286293        # Pick a default server
    287         sockdir = DotXpra()
     294        sockdir = DotXpra(opts.sockdir)
    288295        servers = sockdir.sockets()
    289296        live_servers = [display
    290297                        for (state, display) in servers
     
    327334        return TwoFileConnection(child.stdin, child.stdout, abort_test)
    328335
    329336    elif XPRA_LOCAL_SERVERS_SUPPORTED and display_desc["type"] == "unix-domain":
    330         sockdir = DotXpra()
     337        sockdir = DotXpra(display_desc["sockdir"])
    331338        sock = socket.socket(socket.AF_UNIX)
    332339        return _socket_connect(sock,
    333340                               sockdir.socket_path(display_desc["display"]))
     
    361368        from xpra.client_base import VersionXpraClient
    362369        app = VersionXpraClient(conn, opts)
    363370    else:
     371        #before we go into the client class, we need to pass the sockfile for mmap-group option...
     372        display_name = extra_args[0]
     373        dotxpra = DotXpra(opts.sockdir)
     374        sockfile = dotxpra.socket_path(display_name)
     375        opts.sockfile = sockfile
     376
    364377        from xpra.client import XpraClient
    365378        app = XpraClient(conn, opts)
    366379    def got_gibberish_msg(obj, data):
     
    405418    while conn.read(4096):
    406419        pass
    407420    if display_desc["local"]:
    408         sockdir = DotXpra()
     421        sockdir = DotXpra(opts.sockdir)
    409422        for _ in xrange(6):
    410423            final_state = sockdir.server_state(display_desc["display"])
    411424            if final_state is DotXpra.LIVE:
     
    431444    assert "gtk" not in sys.modules
    432445    if extra_args:
    433446        parser.error("too many arguments for mode")
    434     sockdir = DotXpra()
     447    sockdir = DotXpra(opts.sockdir)
    435448    results = sockdir.sockets()
    436449    if not results:
    437450        sys.stdout.write("No xpra sessions found\n")
  • trunk/src/xpra/scripts/server.py

     
    1515import atexit
    1616import signal
    1717import socket
     18import os
    1819
    1920from xpra.wait_for_x_server import wait_for_x_server        #@UnresolvedImport
    2021from xpra.dotxpra import DotXpra, ServerSockInUse
    2122
     23from stat import S_IRUSR,S_IWUSR,S_IRGRP,S_IWGRP
     24
    2225_cleanups = []
    2326def run_cleanups():
    2427    for c in _cleanups:
     
    136139def create_unix_domain_socket(sockpath):
    137140    listener = socket.socket(socket.AF_UNIX)
    138141    listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     142    #is this a race condition?
    139143    listener.bind(sockpath)
     144    os.chmod(sockpath, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
    140145    return listener
    141146
    142147def create_tcp_socket(parser, spec):
     
    181186    assert mode in ("start", "upgrade")
    182187    upgrading = (mode == "upgrade")
    183188
    184     dotxpra = DotXpra()
     189    dotxpra = DotXpra(opts.sockdir)
    185190
    186191    # This used to be given a display-specific name, but now we give it a
    187192    # single fixed name and if multiple servers are started then the last one
     
    191196    # is running on the remote host.  Might need to revisit this later if
    192197    # people run into problems or autodiscovery turns out to be less useful
    193198    # than expected.
    194     scriptpath = os.path.join(dotxpra.dir(), "run-xpra")
     199    scriptpath = os.path.join(dotxpra.logdir(), "run-xpra")
    195200
    196201    # Save the starting dir now, because we'll lose track of it when we
    197202    # daemonize:
     
    201206    # Daemonize:
    202207    if opts.daemon:
    203208        try:
    204             logpath = dotxpra.server_socket_path(display_name, clobber) + ".log"
     209            sockpath = dotxpra.server_socket_path(display_name, clobber)
    205210        except ServerSockInUse:
    206211            parser.error("You already have an xpra server running at %s\n"
    207212                         "  (did you want 'xpra upgrade'?)"
    208213                         % (display_name,))
     214        logpath = dotxpra.log_path(display_name) + ".log"
    209215        sys.stderr.write("Entering daemon mode; "
    210216                         + "any further errors will be reported to:\n"
    211217                         + ("  %s\n" % logpath))
     
    299305        save_pid(xvfb_pid)
    300306
    301307    sockets = []
    302     sockpath = dotxpra.server_socket_path(display_name, clobber)
    303308    #print("creating server socket %s" % sockpath)
    304309    sockets.append(create_unix_domain_socket(sockpath))
    305310    def cleanup_socket():