diff options
author | Hans de Goede <hdegoede@redhat.com> | 2014-01-22 11:32:56 +0100 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2014-03-03 08:13:54 +0100 |
commit | 6b79f28f5cb259f2168ecc3034fe2161e969bf7d (patch) | |
tree | 9db455dd6b0a23e04b029505bf4c64c18790b853 | |
parent | 701b7ab34984b0f9f0c357b0ff8b53c5132c6324 (diff) |
linux: xf86OpenConsole: Don't detach from controlling tty when it is our vt
Detaching from our controlling tty makes little sense when it is the same
as the vt we're asked to run on. So automatically assume -keeptty in this case.
This is useful to do because when not running as root the server can only make
various VT related ioctls when it does not detach from the tty.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | hw/xfree86/os-support/linux/lnx_init.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c index 9ccf26144..85709c629 100644 --- a/hw/xfree86/os-support/linux/lnx_init.c +++ b/hw/xfree86/os-support/linux/lnx_init.c @@ -79,9 +79,10 @@ switch_to(int vt, const char *from) void xf86OpenConsole(void) { - int i, fd = -1, ret; + int i, fd = -1, ret, current_vt = -1; struct vt_mode VT; struct vt_stat vts; + struct stat st; MessageType from = X_PROBED; const char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL }; const char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; @@ -126,6 +127,22 @@ xf86OpenConsole(void) xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); + /* Some of stdin / stdout / stderr maybe redirected to a file */ + for (i = STDIN_FILENO; i <= STDERR_FILENO; i++) { + ret = fstat(i, &st); + if (ret == 0 && S_ISCHR(st.st_mode) && major(st.st_rdev) == 4) { + current_vt = minor(st.st_rdev); + break; + } + } + + if (!KeepTty && current_vt == xf86Info.vtno) { + xf86Msg(X_PROBED, + "controlling tty is VT number %d, auto-enabling KeepTty\n", + current_vt); + KeepTty = TRUE; + } + if (!KeepTty) { pid_t ppid = getppid(); pid_t ppgid; |