From ca8f26f63694c27fa488a3b58ea6f00b7dd50f81 Mon Sep 17 00:00:00 2001 From: Gaetan Nadon Date: Tue, 25 Mar 2014 13:48:52 -0400 Subject: [PATCH 1/8] suid: replace deprecated AC_HELP_STRING with AS_HELP_STRING Fixes automake warning. Signed-off-by: Gaetan Nadon Signed-off-by: Peter Hutterer Reviewed-by: Peter Hutterer --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index a75ba8f69..f05141420 100644 --- a/configure.ac +++ b/configure.ac @@ -624,8 +624,8 @@ AC_ARG_ENABLE(clientids, AS_HELP_STRING([--disable-clientids], [Build Xorg AC_ARG_ENABLE(pciaccess, AS_HELP_STRING([--enable-pciaccess], [Build Xorg with pciaccess library (default: enabled)]), [PCI=$enableval], [PCI=yes]) AC_ARG_ENABLE(linux_acpi, AS_HELP_STRING([--disable-linux-acpi], [Disable building ACPI support on Linux (if available).]), [enable_linux_acpi=$enableval], [enable_linux_acpi=yes]) AC_ARG_ENABLE(linux_apm, AS_HELP_STRING([--disable-linux-apm], [Disable building APM support on Linux (if available).]), [enable_linux_apm=$enableval], [enable_linux_apm=yes]) -AC_ARG_ENABLE(systemd-logind, AC_HELP_STRING([--enable-systemd-logind], [Build systemd-logind support (default: auto)]), [SYSTEMD_LOGIND=$enableval], [SYSTEMD_LOGIND=auto]) -AC_ARG_ENABLE(suid-wrapper, AC_HELP_STRING([--enable-suid-wrapper], [Build suid-root wrapper for legacy driver support on rootless xserver systems (default: no)]), [SUID_WRAPPER=$enableval], [SUID_WRAPPER=no]) +AC_ARG_ENABLE(systemd-logind, AS_HELP_STRING([--enable-systemd-logind], [Build systemd-logind support (default: auto)]), [SYSTEMD_LOGIND=$enableval], [SYSTEMD_LOGIND=auto]) +AC_ARG_ENABLE(suid-wrapper, AS_HELP_STRING([--enable-suid-wrapper], [Build suid-root wrapper for legacy driver support on rootless xserver systems (default: no)]), [SUID_WRAPPER=$enableval], [SUID_WRAPPER=no]) dnl DDXes. AC_ARG_ENABLE(xorg, AS_HELP_STRING([--enable-xorg], [Build Xorg server (default: auto)]), [XORG=$enableval], [XORG=auto]) From b82ef51509bf24e8eafeb615a3e2f4fcd559554e Mon Sep 17 00:00:00 2001 From: Gaetan Nadon Date: Tue, 25 Mar 2014 13:49:02 -0400 Subject: [PATCH 2/8] suid: add generated Xorg.sh to hw/xfree86/.gitignore Signed-off-by: Gaetan Nadon Signed-off-by: Peter Hutterer Reviewed-by: Peter Hutterer --- hw/xfree86/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/xfree86/.gitignore b/hw/xfree86/.gitignore index 997a94efe..fb6830b2c 100644 --- a/hw/xfree86/.gitignore +++ b/hw/xfree86/.gitignore @@ -1,4 +1,5 @@ Xorg +Xorg.sh xorg.conf.example sdksyms.c sdksyms.dep From 6289f71494453d34614b7ff1238840681c2472af Mon Sep 17 00:00:00 2001 From: Gaetan Nadon Date: Tue, 25 Mar 2014 14:00:13 -0400 Subject: [PATCH 3/8] suid: adding Xorg.sh.in to EXTRA_DIST is redundant All files specified in AC_CONFIG_FILES get distributed automatically. Signed-off-by: Gaetan Nadon Signed-off-by: Peter Hutterer Reviewed-by: Peter Hutterer --- hw/xfree86/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am index a315bbc17..418a35a83 100644 --- a/hw/xfree86/Makefile.am +++ b/hw/xfree86/Makefile.am @@ -89,7 +89,7 @@ endif BUILT_SOURCES = xorg.conf.example DISTCLEANFILES = xorg.conf.example -EXTRA_DIST = xorgconf.cpp Xorg.sh.in +EXTRA_DIST = xorgconf.cpp # Without logdir, X will post an error on the terminal and will not start install-data-local: From c0d3a13e7ee42be26d6d1923c9f3ae0355497869 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Mon, 24 Mar 2014 16:31:59 +0100 Subject: [PATCH 4/8] Buildsys: Create SUID_WRAPPER_DIR before using it Signed-off-by: Hans de Goede Signed-off-by: Peter Hutterer Reviewed-by: Peter Hutterer --- hw/xfree86/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am index 418a35a83..8f1390596 100644 --- a/hw/xfree86/Makefile.am +++ b/hw/xfree86/Makefile.am @@ -105,6 +105,7 @@ if INSTALL_SETUID chmod u+s $(DESTDIR)$(bindir)/Xorg endif if SUID_WRAPPER + $(MKDIR_P) $(DESTDIR)$(SUID_WRAPPER_DIR) mv $(DESTDIR)$(bindir)/Xorg $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg.bin ${INSTALL} -m 755 Xorg.sh $(DESTDIR)$(bindir)/Xorg -chown root $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg.wrap && chmod u+s $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg.wrap From dc48bd653c7e1013e2d69e3f59ae3cbc0c893473 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Mon, 24 Mar 2014 16:32:01 +0100 Subject: [PATCH 5/8] systemd-logind: Monitor systemd-logind going away When we're using server managed-fds through systemd-logind, systemd-logind *must* keep running while we are using it, as it does things like drmSetMaster and drmDropMaster for us on vt-switch. On a systemd-logind restart, we cannot simply re-connect since we will then get a different fd for the /dev/dri/card# node, and we've tied a lot of state to the old fd. I've discussed this with the systemd people, and in the future there may be a restart mechanism were systemd-logind passed fds from the old logind to the new logind. But for now there answer is simply: "Don't restart systemd-logind", and there never really is a good reason to restart it. So to ensure unpleasentness if people do decide to restart systemd-logind anyways (or when it crashes), monitor logind going away and make this a fatal error. This avoids getting a hard-hung machine on the next vt-switch and will hopefully quickly educate users to not restart systemd-logind while they have an X session using it active. Signed-off-by: Hans de Goede Signed-off-by: Peter Hutterer Reviewed-by: Peter Hutterer --- hw/xfree86/os-support/linux/systemd-logind.c | 34 ++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/hw/xfree86/os-support/linux/systemd-logind.c b/hw/xfree86/os-support/linux/systemd-logind.c index 62858b062..ed670a88c 100644 --- a/hw/xfree86/os-support/linux/systemd-logind.c +++ b/hw/xfree86/os-support/linux/systemd-logind.c @@ -310,11 +310,32 @@ message_filter(DBusConnection * connection, DBusMessage * message, void *data) dbus_int32_t major, minor; char *pause_str; + dbus_error_init(&error); + + if (dbus_message_is_signal(message, + "org.freedesktop.DBus", "NameOwnerChanged")) { + char *name, *old_owner, *new_owner; + + dbus_message_get_args(message, &error, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_STRING, &old_owner, + DBUS_TYPE_STRING, &new_owner, DBUS_TYPE_INVALID); + if (dbus_error_is_set(&error)) { + LogMessage(X_ERROR, "systemd-logind: NameOwnerChanged: %s\n", + error.message); + dbus_error_free(&error); + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + + if (name && strcmp(name, "org.freedesktop.login1") == 0) + FatalError("systemd-logind disappeared (stopped/restarted?)\n"); + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + if (strcmp(dbus_message_get_path(message), info->session) != 0) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - dbus_error_init(&error); - if (dbus_message_is_signal(message, "org.freedesktop.login1.Session", "PauseDevice")) { if (!dbus_message_get_args(message, &error, @@ -472,6 +493,15 @@ connect_hook(DBusConnection *connection, void *data) goto cleanup; } + dbus_bus_add_match(connection, + "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',path='/org/freedesktop/DBus'", + &error); + if (dbus_error_is_set(&error)) { + LogMessage(X_ERROR, "systemd-logind: could not add match: %s\n", + error.message); + goto cleanup; + } + /* * HdG: This is not useful with systemd <= 208 since the signal only * contains invalidated property names there, rather than property, val From f37a46913489397d8628ffe578c8d4ed50b6ca72 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Wed, 26 Mar 2014 12:24:49 +0100 Subject: [PATCH 6/8] configure: Change DEFAULT_LOGPREFIX to really be a filename prefix Rather then a full path prefix, this is a preparation patch for adding support for logging to another location when not running as root. Signed-off-by: Hans de Goede Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- configure.ac | 5 +++-- hw/xfree86/common/xf86Globals.c | 2 +- include/xorg-config.h.in | 5 ++++- include/xwin-config.h.in | 3 --- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index f05141420..bc643e8b6 100644 --- a/configure.ac +++ b/configure.ac @@ -2042,7 +2042,7 @@ if test "x$XORG" = xyes; then XF86CONFIGDIR="xorg.conf.d" AC_SUBST(XF86CONFIGDIR) CONFIGFILE="$sysconfdir/$XF86CONFIGFILE" - LOGPREFIX="$logdir/Xorg." + LOGPREFIX="Xorg." AC_DEFINE(XORG_SERVER, 1, [Building Xorg server]) AC_DEFINE(XORGSERVER, 1, [Building Xorg server]) AC_DEFINE(XFree86Server, 1, [Building XFree86 server]) @@ -2055,7 +2055,8 @@ if test "x$XORG" = xyes; then AC_DEFINE_DIR(__XCONFIGDIR__, XF86CONFIGDIR, [Name of configuration directory]) AC_DEFINE_DIR(DEFAULT_MODULE_PATH, moduledir, [Default module search path]) AC_DEFINE_DIR(DEFAULT_LIBRARY_PATH, libdir, [Default library install path]) - AC_DEFINE_DIR(DEFAULT_LOGPREFIX, LOGPREFIX, [Default log location]) + AC_DEFINE_DIR(DEFAULT_LOGDIR, logdir, [Default log location]) + AC_DEFINE_DIR(DEFAULT_LOGPREFIX, LOGPREFIX, [Default logfile prefix]) AC_DEFINE_UNQUOTED(__VENDORDWEBSUPPORT__, ["$VENDOR_WEB"], [Vendor web address for support]) if test "x$VGAHW" = xyes; then AC_DEFINE(WITH_VGAHW, 1, [Building vgahw module]) diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c index 7df7a80c4..984c39bca 100644 --- a/hw/xfree86/common/xf86Globals.c +++ b/hw/xfree86/common/xf86Globals.c @@ -143,7 +143,7 @@ const char *xf86ConfigFile = NULL; const char *xf86ConfigDir = NULL; const char *xf86ModulePath = DEFAULT_MODULE_PATH; MessageType xf86ModPathFrom = X_DEFAULT; -const char *xf86LogFile = DEFAULT_LOGPREFIX; +const char *xf86LogFile = DEFAULT_LOGDIR "/" DEFAULT_LOGPREFIX; MessageType xf86LogFileFrom = X_DEFAULT; Bool xf86LogFileWasOpened = FALSE; serverLayoutRec xf86ConfigLayout = { NULL, }; diff --git a/include/xorg-config.h.in b/include/xorg-config.h.in index 77a1aae55..4e2a45b98 100644 --- a/include/xorg-config.h.in +++ b/include/xorg-config.h.in @@ -45,7 +45,10 @@ /* Path to installed libraries. */ #undef DEFAULT_LIBRARY_PATH -/* Path to server log file. */ +/* Default log location */ +#undef DEFAULT_LOGDIR + +/* Default logfile prefix */ #undef DEFAULT_LOGPREFIX /* Building DRI-capable DDX. */ diff --git a/include/xwin-config.h.in b/include/xwin-config.h.in index 176c01980..a5e6b17b3 100644 --- a/include/xwin-config.h.in +++ b/include/xwin-config.h.in @@ -26,8 +26,5 @@ /* Vendor web address for support */ #undef __VENDORDWEBSUPPORT__ -/* Default log location */ -#undef DEFAULT_LOGDIR - /* Whether we should re-locate the root to where the executable lives */ #undef RELOCATE_PROJECTROOT From 9d65c515d83d2158b5949e249777ca2a02b31901 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Tue, 1 Apr 2014 11:24:17 +0200 Subject: [PATCH 7/8] xf86LogInit: log to XDG_DATA_HOME when not running as root When no logfile was specified (xf86LogFileFrom == X_DEFAULT) and we're not running as root log to $XDG_DATA_HOME/xorg/Xorg.#.log as Xorg won't be able to log to the default /var/log/... when it is not running as root. Signed-off-by: Hans de Goede Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- configure.ac | 4 ++++ hw/xfree86/common/xf86Helper.c | 31 ++++++++++++++++++++++++++++++- hw/xfree86/man/Xorg.man | 6 ++++-- hw/xfree86/man/xorg.conf.man | 6 +++++- include/xorg-config.h.in | 6 ++++++ 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index bc643e8b6..cdd3258e4 100644 --- a/configure.ac +++ b/configure.ac @@ -2043,6 +2043,8 @@ if test "x$XORG" = xyes; then AC_SUBST(XF86CONFIGDIR) CONFIGFILE="$sysconfdir/$XF86CONFIGFILE" LOGPREFIX="Xorg." + XDG_DATA_HOME=".local/share" + XDG_DATA_HOME_LOGDIR="xorg" AC_DEFINE(XORG_SERVER, 1, [Building Xorg server]) AC_DEFINE(XORGSERVER, 1, [Building Xorg server]) AC_DEFINE(XFree86Server, 1, [Building XFree86 server]) @@ -2057,6 +2059,8 @@ if test "x$XORG" = xyes; then AC_DEFINE_DIR(DEFAULT_LIBRARY_PATH, libdir, [Default library install path]) AC_DEFINE_DIR(DEFAULT_LOGDIR, logdir, [Default log location]) AC_DEFINE_DIR(DEFAULT_LOGPREFIX, LOGPREFIX, [Default logfile prefix]) + AC_DEFINE_DIR(DEFAULT_XDG_DATA_HOME, XDG_DATA_HOME, [Default XDG_DATA dir under HOME]) + AC_DEFINE_DIR(DEFAULT_XDG_DATA_HOME_LOGDIR, XDG_DATA_HOME_LOGDIR, [Default log dir under XDG_DATA_HOME]) AC_DEFINE_UNQUOTED(__VENDORDWEBSUPPORT__, ["$VENDOR_WEB"], [Vendor web address for support]) if test "x$VGAHW" = xyes; then AC_DEFINE(WITH_VGAHW, 1, [Building vgahw module]) diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index 12a877159..e2b32a074 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -1217,16 +1217,45 @@ xf86ErrorF(const char *format, ...) va_end(ap); } +/* Note temporarily modifies the passed in buffer! */ +static void xf86_mkdir_p(char *path) +{ + char *sep = path; + + while ((sep = strchr(sep + 1, '/'))) { + *sep = 0; + (void)mkdir(path, 0777); + *sep = '/'; + } + (void)mkdir(path, 0777); +} + void xf86LogInit(void) { - char *lf = NULL; + char *env, *lf = NULL; + char buf[PATH_MAX]; #define LOGSUFFIX ".log" #define LOGOLDSUFFIX ".old" /* Get the log file name */ if (xf86LogFileFrom == X_DEFAULT) { + /* When not running as root, we won't be able to write to /var/log */ + if (geteuid() != 0) { + if ((env = getenv("XDG_DATA_HOME"))) + snprintf(buf, sizeof(buf), "%s/%s", env, + DEFAULT_XDG_DATA_HOME_LOGDIR); + else if ((env = getenv("HOME"))) + snprintf(buf, sizeof(buf), "%s/%s/%s", env, + DEFAULT_XDG_DATA_HOME, DEFAULT_XDG_DATA_HOME_LOGDIR); + + if (env) { + xf86_mkdir_p(buf); + strlcat(buf, "/" DEFAULT_LOGPREFIX, sizeof(buf)); + xf86LogFile = buf; + } + } /* Append the display number and ".log" */ if (asprintf(&lf, "%s%%s" LOGSUFFIX, xf86LogFile) == -1) FatalError("Cannot allocate space for the log file name\n"); diff --git a/hw/xfree86/man/Xorg.man b/hw/xfree86/man/Xorg.man index 0cd5a1068..3ff6aef89 100644 --- a/hw/xfree86/man/Xorg.man +++ b/hw/xfree86/man/Xorg.man @@ -301,9 +301,11 @@ Use the file called .I filename as the .B Xorg -server log file. The default log file is +server log file. The default log file when running as root is .BI __logdir__/Xorg. n .log -on most platforms, where +and for non root it is +.BI $XDG_DATA_HOME/xorg/Xorg. n .log +where .I n is the display number of the .B Xorg diff --git a/hw/xfree86/man/xorg.conf.man b/hw/xfree86/man/xorg.conf.man index 85f9f2ee1..6d2652e84 100644 --- a/hw/xfree86/man/xorg.conf.man +++ b/hw/xfree86/man/xorg.conf.man @@ -442,11 +442,15 @@ __modulepath__ .TP 7 .BI "LogFile \*q" path \*q sets the name of the Xorg server log file. -The default log file name is +The default log file name when running as root is .PP .RS 11 .RI __logdir__/Xorg. .log .RE +and for non root it is +.RS 11 +.RI $XDG_DATA_HOME/xorg/Xorg. .log +.RE .PP .RS 7 where diff --git a/include/xorg-config.h.in b/include/xorg-config.h.in index 4e2a45b98..629ae4057 100644 --- a/include/xorg-config.h.in +++ b/include/xorg-config.h.in @@ -51,6 +51,12 @@ /* Default logfile prefix */ #undef DEFAULT_LOGPREFIX +/* Default XDG_DATA dir under HOME */ +#undef DEFAULT_XDG_DATA_HOME + +/* Default log dir under XDG_DATA_HOME */ +#undef DEFAULT_XDG_DATA_HOME_LOGDIR + /* Building DRI-capable DDX. */ #undef XF86DRI From 98924719d524bf87cdf301063cd744d1271c33ff Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 2 Apr 2014 13:55:10 +1000 Subject: [PATCH 8/8] Revert "xkb: ProcesssPointerEvent must work on the VCP if it gets the VCP" This was the wrong fix to the problem, and it triggered a change in XKB behavior: previously a button event would unlock a latched modifier, now it doesn't anymore. https://bugs.freedesktop.org/show_bug.cgi?id=73155 Note that the new behavior is is strictly spec compliant but we've had the other behavior for a long time so we shouldn't break it. The bug this patch originally fixed was a null-pointer dereference when releasing button events on server shutdown. This was addressed by the commit below, so the need for this patch has gone away anyway. commit 3e4be4033aed78b2bb3a18d51f0963989efd1af3 Author: Peter Hutterer Date: Fri Jan 25 11:47:32 2013 +1000 dix: when shutting down slave devices, shut down xtest devices last This reverts commit 2decff6393a44b56d80d53570718f95354fde454. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- xkb/xkbAccessX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c index cb4bca008..5f3de0d9e 100644 --- a/xkb/xkbAccessX.c +++ b/xkb/xkbAccessX.c @@ -711,7 +711,7 @@ ProcessPointerEvent(InternalEvent *ev, DeviceIntPtr mouse) xkbDeviceInfoPtr xkbPrivPtr = XKBDEVICEINFO(mouse); DeviceEvent *event = &ev->device_event; - dev = (IsMaster(mouse) || IsFloating(mouse)) ? mouse : GetMaster(mouse, MASTER_KEYBOARD); + dev = IsFloating(mouse) ? mouse : GetMaster(mouse, MASTER_KEYBOARD); if (dev && dev->key) { xkbi = dev->key->xkbInfo;