aboutsummaryrefslogtreecommitdiff
path: root/debian/patches/027_nxcomp_abstract-X11-socket.full+lite.patch
blob: 4f614338cd51e19e05de87d097d623065d826d56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
diff --git a/nxcomp/Loop.cpp b/nxcomp/Loop.cpp
index 92b6fc2..d86809d 100644
--- a/nxcomp/Loop.cpp
+++ b/nxcomp/Loop.cpp
@@ -4250,6 +4250,39 @@ int SetupDisplaySocket(int &xServerAddrFamily, sockaddr *&xServerAddr,
     // where the socket will be created.
     //
 
+    // Try abstract X11 socket first (via a test connect), if that fails
+    // fall back to Unix domain socket file.
+
+    #ifdef __linux__
+    int testSocketFD;
+    testSocketFD = socket(xServerAddrFamily, SOCK_STREAM, PF_UNSPEC);
+
+    int len = sprintf(unixSocketName + 1, "/tmp/.X11-unix/X%d", xPort);
+    unixSocketName[0] = '\0';
+
+    sockaddr_un *xServerAddrABSTRACT = new sockaddr_un;
+    memset(xServerAddrABSTRACT, 0, xServerAddrLength);
+    xServerAddrABSTRACT -> sun_family = AF_UNIX;
+    memcpy(xServerAddrABSTRACT -> sun_path, unixSocketName, len+1);
+    xServerAddrLength = len +3;
+
+    int ret = connect(testSocketFD, (struct sockaddr *) xServerAddrABSTRACT, xServerAddrLength);
+    if (ret == 0) {
+
+        cerr << "Info" << ": Using abstract X11 socket in kernel namespace "
+             << "for accessing DISPLAY=:" << xPort << ".\n";
+
+        close(testSocketFD);
+        xServerAddr = (sockaddr *) xServerAddrABSTRACT;
+        return 1;
+
+    } else {
+
+        cerr << "Info" << ": Falling back to file system X11 socket "
+             << "for accessing DISPLAY=:" << xPort << ".\n";
+
+    #endif
+
     struct stat statInfo;
 
     char unixSocketDir[DEFAULT_STRING_LENGTH];
@@ -4322,6 +4355,11 @@ int SetupDisplaySocket(int &xServerAddrFamily, sockaddr *&xServerAddr,
 
     xServerAddr = (sockaddr *) xServerAddrUNIX;
     xServerAddrLength = sizeof(sockaddr_un);
+
+    #ifdef __linux__
+
+    }
+    #endif
   }
   else
   {