summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Bono <alessandro.bono369@gmail.com>2023-04-03 15:09:28 +0200
committerPeter Hutterer <peter.hutterer@who-t.net>2023-04-06 00:48:12 +0000
commitbddcaf08867c449ad847db6adf1ca32f42977de0 (patch)
tree00c7bc91f075700e16e16bd25530cdbda2f5db17
parent81458a86bf9320a6d40d5cba64f66840f15eb26c (diff)
downloadxserver-bddcaf08867c449ad847db6adf1ca32f42977de0.tar.gz
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.
-rw-r--r--xkb/ddxLoad.c13
1 files changed, 11 insertions, 2 deletions
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 = "\\";