xserver: Branch 'master'

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Apr 6 00:50:43 UTC 2023


 xkb/ddxLoad.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

New commits:
commit bddcaf08867c449ad847db6adf1ca32f42977de0
Author: Alessandro Bono <alessandro.bono369 at gmail.com>
Date:   Mon Apr 3 15:09:28 2023 +0200

    ddxLoad: Check XDG_RUNTIME_DIR before fallback to /tmp/
    
    The XKM_OUTPUT_DIR folder by default is defined as ${datadir}/X11/xkb/compiled
    and it is usually defined as /var/lib/xkb or %{_localstatedir}/lib/xkb by
    distributions. If X is executed as non-root it won't have permissions to write
    into that folder. If we fallback directly to /tmp we might get name collisions:
    ```
    > Error: Cannot open "/tmp/server-10.xkm" to write keyboard description
    > Exiting
    ```
    
    Where the file /tmp/server-10.xkm already exists but is owned by another user
    that previously executed X and had the display number 10. This is specially
    problematic when exeuting Xvfb.
    
    Before falling back to /tmp/ check first the XDG_RUNTIME_DIR.

diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
index 2d203ce11..18814264a 100644
--- a/xkb/ddxLoad.c
+++ b/xkb/ddxLoad.c
@@ -31,6 +31,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <xkb-config.h>
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <ctype.h>
 #include <X11/X.h>
 #include <X11/Xos.h>
@@ -69,9 +70,17 @@ OutputDirectory(char *outdir, size_t size)
     /* Can we write an xkm and then open it too? */
     if (access(XKM_OUTPUT_DIR, W_OK | X_OK) == 0) {
         directory = XKM_OUTPUT_DIR;
-        if (XKM_OUTPUT_DIR[strlen(XKM_OUTPUT_DIR) - 1] != '/')
-            pathsep = "/";
+    } else {
+        const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
+
+        if (xdg_runtime_dir && xdg_runtime_dir[0] == '/' &&
+            access(xdg_runtime_dir, W_OK | X_OK) == 0)
+            directory = xdg_runtime_dir;
     }
+
+    if (directory && directory[strlen(directory) - 1] != '/')
+        pathsep = "/";
+
 #else
     directory = Win32TempDir();
     pathsep = "\\";


More information about the xorg-commit mailing list