linux: Add a may_fail paramter to linux_parse_vt_settings

linux_parse_vt_settings() was split out of xf86OpenConsole so that it can
be called earlier during systemd-logind init, but it is possible to run
the xserver in such a way that xf86OpenConsole() is never used.

The FatalError calls in linux_parse_vt_settings() may stop the Xorg xserver
from working when e.g. no /dev/tty0 is present in such a setup.

This commit adds a may_fail parameter to linux_parse_vt_settings() which
can be used to make linux_parse_vt_settings() fail silenty with an error
return in this case, rather then calling FatalError().

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Hans de Goede 2015-05-13 13:17:09 +02:00
parent 1dba5a0b19
commit 81bcada14e
2 changed files with 22 additions and 9 deletions

View File

@ -26,7 +26,7 @@
#ifndef XF86_LINUX_H #ifndef XF86_LINUX_H
#define XF86_LINUX_H #define XF86_LINUX_H
void linux_parse_vt_settings(void); int linux_parse_vt_settings(int may_fail);
int linux_get_keeptty(void); int linux_get_keeptty(void);
#endif #endif

View File

@ -80,8 +80,8 @@ switch_to(int vt, const char *from)
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral" #pragma GCC diagnostic ignored "-Wformat-nonliteral"
void int
linux_parse_vt_settings(void) linux_parse_vt_settings(int may_fail)
{ {
int i, fd = -1, ret, current_vt = -1; int i, fd = -1, ret, current_vt = -1;
struct vt_stat vts; struct vt_stat vts;
@ -93,7 +93,7 @@ linux_parse_vt_settings(void)
static int vt_settings_parsed = 0; static int vt_settings_parsed = 0;
if (vt_settings_parsed) if (vt_settings_parsed)
return; return 1;
/* /*
* setup the virtual terminal manager * setup the virtual terminal manager
@ -110,24 +110,36 @@ linux_parse_vt_settings(void)
i++; i++;
} }
if (fd < 0) if (fd < 0) {
if (may_fail)
return 0;
FatalError("parse_vt_settings: Cannot open /dev/tty0 (%s)\n", FatalError("parse_vt_settings: Cannot open /dev/tty0 (%s)\n",
strerror(errno)); strerror(errno));
}
if (xf86Info.ShareVTs) { if (xf86Info.ShareVTs) {
SYSCALL(ret = ioctl(fd, VT_GETSTATE, &vts)); SYSCALL(ret = ioctl(fd, VT_GETSTATE, &vts));
if (ret < 0) if (ret < 0) {
if (may_fail)
return 0;
FatalError("parse_vt_settings: Cannot find the current" FatalError("parse_vt_settings: Cannot find the current"
" VT (%s)\n", strerror(errno)); " VT (%s)\n", strerror(errno));
}
xf86Info.vtno = vts.v_active; xf86Info.vtno = vts.v_active;
} }
else { else {
SYSCALL(ret = ioctl(fd, VT_OPENQRY, &xf86Info.vtno)); SYSCALL(ret = ioctl(fd, VT_OPENQRY, &xf86Info.vtno));
if (ret < 0) if (ret < 0) {
if (may_fail)
return 0;
FatalError("parse_vt_settings: Cannot find a free VT: " FatalError("parse_vt_settings: Cannot find a free VT: "
"%s\n", strerror(errno)); "%s\n", strerror(errno));
if (xf86Info.vtno == -1) }
if (xf86Info.vtno == -1) {
if (may_fail)
return 0;
FatalError("parse_vt_settings: Cannot find a free VT\n"); FatalError("parse_vt_settings: Cannot find a free VT\n");
}
} }
close(fd); close(fd);
} }
@ -151,6 +163,7 @@ linux_parse_vt_settings(void)
} }
vt_settings_parsed = 1; vt_settings_parsed = 1;
return 1;
} }
int int
@ -168,7 +181,7 @@ xf86OpenConsole(void)
const char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; const char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
if (serverGeneration == 1) { if (serverGeneration == 1) {
linux_parse_vt_settings(); linux_parse_vt_settings(FALSE);
if (!KeepTty) { if (!KeepTty) {
pid_t ppid = getppid(); pid_t ppid = getppid();