xfree86: On Linux, while only seat0 can have TTYs, don't assmume all seat0s have TTYs

This commit is contained in:
nerdopolis 2021-10-08 21:51:43 -04:00 committed by Povilas Kanapickas
parent d7d6e6a4ed
commit b8c12aac65
3 changed files with 21 additions and 2 deletions

View File

@ -85,6 +85,11 @@
#include <X11/extensions/dpmsconst.h> #include <X11/extensions/dpmsconst.h>
#include "dpmsproc.h" #include "dpmsproc.h"
#endif #endif
#ifdef __linux__
#include <linux/major.h>
#include <sys/sysmacros.h>
#endif
#include <hotplug.h> #include <hotplug.h>
void (*xf86OSPMClose) (void) = NULL; void (*xf86OSPMClose) (void) = NULL;
@ -201,6 +206,17 @@ xf86PrivsElevated(void)
return PrivsElevated(); return PrivsElevated();
} }
Bool
xf86HasTTYs(void)
{
#ifdef __linux__
struct stat tty0devAttributes;
return (stat("/dev/tty0", &tty0devAttributes) == 0 && major(tty0devAttributes.st_rdev) == TTY_MAJOR);
#else
return TRUE;
#endif
}
static void static void
xf86AutoConfigOutputDevices(void) xf86AutoConfigOutputDevices(void)
{ {
@ -425,7 +441,7 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
want_hw_access = TRUE; want_hw_access = TRUE;
/* Non-seat0 X servers should not open console */ /* Non-seat0 X servers should not open console */
if (!(flags & HW_SKIP_CONSOLE) && !ServerIsNotSeat0()) if (!(flags & HW_SKIP_CONSOLE) && !ServerIsNotSeat0() && xf86HasTTYs())
xorgHWOpenConsole = TRUE; xorgHWOpenConsole = TRUE;
} }

View File

@ -158,6 +158,8 @@ extern _X_EXPORT Bool
xf86CallDriverProbe(struct _DriverRec *drv, Bool detect_only); xf86CallDriverProbe(struct _DriverRec *drv, Bool detect_only);
extern _X_EXPORT Bool extern _X_EXPORT Bool
xf86PrivsElevated(void); xf86PrivsElevated(void);
extern _X_EXPORT Bool
xf86HasTTYs(void);
#endif /* _NO_XF86_PROTOTYPES */ #endif /* _NO_XF86_PROTOTYPES */

View File

@ -38,6 +38,7 @@
#include "xf86.h" #include "xf86.h"
#include "xf86platformBus.h" #include "xf86platformBus.h"
#include "xf86Xinput.h" #include "xf86Xinput.h"
#include "xf86Priv.h"
#include "globals.h" #include "globals.h"
#include "systemd-logind.h" #include "systemd-logind.h"
@ -583,7 +584,7 @@ static struct dbus_core_hook core_hook = {
int int
systemd_logind_init(void) systemd_logind_init(void)
{ {
if (!ServerIsNotSeat0() && linux_parse_vt_settings(TRUE) && !linux_get_keeptty()) { if (!ServerIsNotSeat0() && xf86HasTTYs() && linux_parse_vt_settings(TRUE) && !linux_get_keeptty()) {
LogMessage(X_INFO, LogMessage(X_INFO,
"systemd-logind: logind integration requires -keeptty and " "systemd-logind: logind integration requires -keeptty and "
"-keeptty was not provided, disabling logind integration\n"); "-keeptty was not provided, disabling logind integration\n");