]> git.meshlink.io Git - meshlink/commitdiff
Let the GUI use UNIX sockets if available.
authorGuus Sliepen <guus@tinc-vpn.org>
Thu, 7 Feb 2013 14:27:16 +0000 (15:27 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Thu, 7 Feb 2013 14:27:16 +0000 (15:27 +0100)
gui/tinc-gui

index 9c6485f8a929b7fcab75a334bb262c4c0c0cff46..2b4f903441435abd898f3eb51e3dcb0b3ff90c4b 100755 (executable)
@@ -111,11 +111,28 @@ class VPN:
        piddir = '/var/run/'
 
        def connect(self):
+               # read the pidfile
                f = open(self.pidfile)
                info = string.split(f.readline())
                f.close()
-               s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-               s.connect((info[2], int(info[4])))
+
+               # check if there is a UNIX socket as well
+               if self.pidfile.endswith(".pid"):
+                       unixfile = self.pidfile.replace(".pid", ".socket");
+               else:
+                       unixfile = self.pidfile + ".socket";
+
+               if os.path.exists(unixfile):
+                       # use it if it exists
+                       print(unixfile + " exists!");
+                       s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+                       s.connect(unixfile)
+               else:
+                       # otherwise connect via TCP
+                       print(unixfile + " does not exist.");
+                       s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+                       s.connect((info[2], int(info[4])))
+
                self.sf = s.makefile()
                s.close()
                hello = string.split(self.sf.readline())