Hi Nathaniel,

Please consider this patch for merging.
Summary of the changes:
* adds "--no-ipc" option for turning off unix domain socket listener.
* adds "--tcp" option for turning on the TCP listener.
* adds "--tcp-offset" option to change the TCP port number offset
(defaults to 16000)
* adds "--host" option to change the host that the TCP listener will
bind to (defaults to 127.0.0.1)
* adds "--port" option to override the offset/displayNo and specify the
port number directly. (1)
* adds support for "tcp:[portNumber]" syntax for the client.
Which will connect to a TCP socket. (using the switches above)
* splits the constructor for XpraServer into 4 methods: init_wm,
init_socket_tcp, init_socket_ipc, init_keymap
(it is a bit more readable this way)
* _new_connection now takes the listener as a parameter (as there may be
2 listeners active)
* updates to the documentation.

(1) I know you were not keen on supporting the "--port" option, but
after some testing with a bunch of scripts I find it difficult not to
require it, ie: scripts that stop and start xpra sessions should not
make any assumptions about the offset/port numbers used, they may locate
the server using the tcp socket only (lsof). It is much nicer to allow
the client to connect to a fixed address (port+host) rather than have to
resort to computations using display numbers and offset that the shell
script should have no knowledge of...

Thanks
Antoine
diff -ur parti-all-0.0.5-vanilla/xpra/scripts/main.py parti-all-0.0.5/xpra/scripts/main.py
--- parti-all-0.0.5-vanilla/xpra/scripts/main.py	2008-11-02 15:29:13.000000000 +0700
+++ parti-all-0.0.5/xpra/scripts/main.py	2009-03-09 16:42:32.000000000 +0700
@@ -1,4 +1,4 @@
-import gobject
+import gobjepct
 import sys
 import os
 import socket
@@ -44,6 +44,21 @@
     parser.add_option("--no-daemon", action="store_false",
                       dest="daemon", default=True,
                       help="Don't daemonize when running as a server")
+    parser.add_option("--no-ipc", action="store_false",
+                      dest="ipc", default=True,
+                      help="Disable IPC socket listener")
+    parser.add_option("--tcp", action="store_true",
+                      dest="tcp", default=False,
+                      help="Enable the TCP socket listener")
+    parser.add_option("--tcp-offset", action="append",
+                      dest="offset", default=16000,
+                      help="Set the offset used to calculate the TCP socket listener's port number")
+    parser.add_option("--host", action="append",
+                      dest="host", default="127.0.0.1",
+                      help="Set the host or IP address that the TCP listener will bind to")
+    parser.add_option("--port", action="append",
+                      dest="port", default=None,
+                      help="Set the port number that the TCP listener will bind to")
     parser.add_option("--remote-xpra", action="store",
                       dest="remote_xpra", default=None, metavar="CMD",
                       help="How to run 'xpra' on the remote host")
@@ -123,11 +138,24 @@
                              stdin=b.fileno(), stdout=b.fileno(),
                              bufsize=0)
         return a, False
-    else:
+    elif display_name.startswith(":"):
         sockdir = DotXpra()
         sock = socket.socket(socket.AF_UNIX)
         sock.connect(sockdir.socket_path(display_name))
         return sock, True
+    elif display_name.startswith("tcp:"):
+        display_no = display_name[4:]
+        if opts.port:
+            port = opts.port
+        else:
+            port = opts.offset + int(display_no)
+        display_args = [":" + display_no]
+        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        sock.connect((opts.host, port))
+        return	sock, True
+    else
+        parser.error("unknown format for display name")
+        
 
 def run_client(parser, opts, extra_args):
     from xpra.client import XpraClient
diff -ur parti-all-0.0.5-vanilla/xpra/scripts/server.py parti-all-0.0.5/xpra/scripts/server.py
--- parti-all-0.0.5-vanilla/xpra/scripts/server.py	2008-11-02 15:29:13.000000000 +0700
+++ parti-all-0.0.5/xpra/scripts/server.py	2009-03-09 16:49:20.000000000 +0700
@@ -129,6 +129,18 @@
         print "--exit-with-children specified without any children to spawn; exiting immediately"
         return
 
+    #sanity check for socket options:
+    if not opts.ipc and not opts.tcp:
+        print "if using --no-ipc, you should at least set --tcp : you need at least one socket listener!"
+        return
+    port=None
+    if opts.tcp:
+	if opts.port:
+		port = opts.port
+	else:
+		display_number = int(display_name[1:])
+		port = opts.offset + display_number
+
     atexit.register(run_cleanups)
     signal.signal(signal.SIGINT, deadly_signal)
     signal.signal(signal.SIGTERM, deadly_signal)
@@ -243,7 +255,7 @@
 
     # This import is delayed because the module depends on gtk:
     import xpra.server
-    app = xpra.server.XpraServer(sockpath, upgrading)
+    app = xpra.server.XpraServer(sockpath, upgrading, opts.ipc, opts.tcp, opts.host, port)
     def cleanup_socket(self):
         print "removing socket"
         try:
diff -ur parti-all-0.0.5-vanilla/xpra/server.py parti-all-0.0.5/xpra/server.py
--- parti-all-0.0.5-vanilla/xpra/server.py	2008-11-02 15:29:13.000000000 +0700
+++ parti-all-0.0.5/xpra/server.py	2009-03-09 16:47:53.000000000 +0700
@@ -199,7 +199,17 @@
         "wimpiggy-child-map-event": one_arg_signal,
         }
 
-    def __init__(self, socketpath, clobber):
+    def __init__(self, socketpath, clobber, use_ipc, use_tcp, host, port):
+        self._socketpath = socketpath
+	self.init_wm(clobber)
+	if use_ipc:
+		self.init_socket_ipc()
+	if use_tcp:
+		self.init_socket_tcp(host, port)
+	self.init_keymap()
+	self.init_clipboards()
+
+    def init_wm(self, clobber):
         gobject.GObject.__init__(self)
         
         # Do this before creating the Wm object, to avoid clobbering its
@@ -231,14 +241,23 @@
             if (is_override_redirect(window) and is_mapped(window)):
                 self._add_new_or_window(window)
 
-        self._socketpath = socketpath
-        self._listener = socket.socket(socket.AF_UNIX)
-        self._listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-        self._listener.bind(self._socketpath)
-        self._listener.listen(5)
-        gobject.io_add_watch(self._listener, gobject.IO_IN,
-                             self._new_connection)
+	
+    def init_socket_tcp(self, host, port):
+	listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        listener.bind((host, port))
+        listener.listen(5)
+        gobject.io_add_watch(listener, gobject.IO_IN, self._new_connection, listener)
+
+
+    def init_socket_ipc(self):
+        listener = socket.socket(socket.AF_UNIX)
+        listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+        listener.bind(self._socketpath)
+        listener.listen(5)
+        gobject.io_add_watch(listener, gobject.IO_IN, self._new_connection, listener)
 
+
+    def init_keymap(self):
         self._keymap = gtk.gdk.keymap_get_default()
         self._keymap.connect("keys-changed", self._keys_changed)
         self._keys_changed()
@@ -288,9 +338,9 @@
         gtk.main()
         return self._upgrading
 
-    def _new_connection(self, *args):
+    def _new_connection(self, listener, *args):
         log.info("New connection received")
-        sock, addr = self._listener.accept()
+        sock, addr = listener.accept()
         self._potential_protocols.append(Protocol(sock, self.process_packet))
         return True
 
diff -ur parti-all-0.0.5-vanilla/xpra.1 parti-all-0.0.5/xpra.1
--- parti-all-0.0.5-vanilla/xpra.1	2008-11-02 15:29:13.000000000 +0700
+++ parti-all-0.0.5/xpra.1	2009-03-09 17:04:41.000000000 +0700
@@ -172,6 +172,34 @@
 prevents that behavior (useful mostly for debugging).
 .SS Options for attach, stop
 .TP
+\fB\-\-no\-ipc\fP
+By default, the xpra server listens for connection on an IPC socket.
+This option disables it. (you will need to enable the TCP socket
+when using this option)
+.SS Options for start
+.TP
+\fB\-\-tcp\fP
+This enables the TCP socket.
+Note that this mode is insecure as any local user may be able to
+attach to this socket.
+.SS Options for start
+.TP
+\fB\-\-host\fP
+This option changes the host that the TCP socket listener will bind
+to (which is 127.0.0.1 by default)
+.SS Options for start
+.TP
+\fB\-\-offset\fP
+This option changes the offset that the TCP socket listener uses to
+calculate the port number (which defaults to 16000).
+The port number is this offset plus the display number.
+.SS Options for start
+.TP
+\fB\-\-port\fP
+This option changes the port number used by the TCP socket listener.
+This option overrides the \fBoffset\fP option.
+.SS Options for start
+.TP
 \fB\-\-remote\-xpra=\fP\fICMD\fP
 When connecting to a remote server over ssh, xpra needs to be able to
 find and run the xpra executable on the remote host.  If this

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Parti-discuss mailing list
[email protected]
http://lists.partiwm.org/cgi-bin/mailman/listinfo/parti-discuss

Reply via email to