aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xfree86/os-support/linux
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-12-01 06:54:34 +0000
committermarha <marha@users.sourceforge.net>2010-12-01 06:54:34 +0000
commit30eaf03aef5847adb6da7efd4bbf4a4abaf5d738 (patch)
tree9096dda170059f36806901aee59b8cf2a839a9e9 /xorg-server/hw/xfree86/os-support/linux
parent57818d0fe4f7cf94279909f03ec11b326b284f1e (diff)
downloadvcxsrv-30eaf03aef5847adb6da7efd4bbf4a4abaf5d738.tar.gz
vcxsrv-30eaf03aef5847adb6da7efd4bbf4a4abaf5d738.tar.bz2
vcxsrv-30eaf03aef5847adb6da7efd4bbf4a4abaf5d738.zip
xserver libX11 libxcb update 1/12/2010
Diffstat (limited to 'xorg-server/hw/xfree86/os-support/linux')
-rw-r--r--xorg-server/hw/xfree86/os-support/linux/lnx_init.c108
1 files changed, 17 insertions, 91 deletions
diff --git a/xorg-server/hw/xfree86/os-support/linux/lnx_init.c b/xorg-server/hw/xfree86/os-support/linux/lnx_init.c
index 7adf0ff73..d1f29d909 100644
--- a/xorg-server/hw/xfree86/os-support/linux/lnx_init.c
+++ b/xorg-server/hw/xfree86/os-support/linux/lnx_init.c
@@ -39,47 +39,14 @@
#include <sys/stat.h>
static Bool KeepTty = FALSE;
-static int VTnum = -1;
static Bool VTSwitch = TRUE;
static Bool ShareVTs = FALSE;
static int activeVT = -1;
-static int vtPermSave[4];
static char vtname[11];
static struct termios tty_attr; /* tty state to restore */
static int tty_mode; /* kbd mode to restore */
-static int
-saveVtPerms(void)
-{
- /* We need to use stat to get permissions. */
- struct stat svtp;
-
- /* Do them numerically ordered, hard coded tty0 first. */
- if (stat("/dev/tty0", &svtp) != 0)
- return 0;
- vtPermSave[0] = (int)svtp.st_uid;
- vtPermSave[1] = (int)svtp.st_gid;
-
- /* Now check the console we are dealing with. */
- if (stat(vtname, &svtp) != 0)
- return 0;
- vtPermSave[2] = (int)svtp.st_uid;
- vtPermSave[3] = (int)svtp.st_gid;
-
- return 1;
-}
-
-static void
-restoreVtPerms(void)
-{
- if (geteuid() == 0) {
- /* Set the terminal permissions back to before we started. */
- (void)chown("/dev/tty0", vtPermSave[0], vtPermSave[1]);
- (void)chown(vtname, vtPermSave[2], vtPermSave[3]);
- }
-}
-
static void *console_handler;
static void
@@ -92,6 +59,16 @@ drain_console(int fd, void *closure)
}
}
+static void
+switch_to(int vt, const char *from)
+{
+ if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, vt) < 0)
+ FatalError("%s: VT_ACTIVATE failed: %s\n", from, strerror(errno));
+
+ if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, vt) < 0)
+ FatalError("%s: VT_WAITACTIVE failed: %s\n", from, strerror(errno));
+}
+
void
xf86OpenConsole(void)
{
@@ -112,8 +89,7 @@ xf86OpenConsole(void)
/*
* setup the virtual terminal manager
*/
- if (VTnum != -1) {
- xf86Info.vtno = VTnum;
+ if (xf86Info.vtno != -1) {
from = X_CMDLINE;
} else {
@@ -179,34 +155,6 @@ xf86OpenConsole(void)
FatalError("xf86OpenConsole: Cannot open virtual console"
" %d (%s)\n", xf86Info.vtno, strerror(errno));
- if (!ShareVTs)
- {
- /*
- * Grab the vt ownership before we overwrite it.
- * Hard coded /dev/tty0 into this function as well for below.
- */
- if (!saveVtPerms())
- xf86Msg(X_WARNING,
- "xf86OpenConsole: Could not save ownership of VT\n");
-
- if (geteuid() == 0) {
- /* change ownership of the vt */
- if (chown(vtname, getuid(), getgid()) < 0)
- xf86Msg(X_WARNING,"xf86OpenConsole: chown %s failed: %s\n",
- vtname, strerror(errno));
-
- /*
- * the current VT device we're running on is not
- * "console", we want to grab all consoles too
- *
- * Why is this needed??
- */
- if (chown("/dev/tty0", getuid(), getgid()) < 0)
- xf86Msg(X_WARNING,"xf86OpenConsole: chown /dev/tty0 failed: %s\n",
- strerror(errno));
- }
- }
-
/*
* Linux doesn't switch to an active vt after the last close of a vt,
* so we do this ourselves by remembering which is active now.
@@ -236,13 +184,7 @@ xf86OpenConsole(void)
/*
* now get the VT. This _must_ succeed, or else fail completely.
*/
- if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0)
- FatalError("xf86OpenConsole: VT_ACTIVATE failed: %s\n",
- strerror(errno));
-
- if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0)
- FatalError("xf86OpenConsole: VT_WAITACTIVE failed: %s\n",
- strerror(errno));
+ switch_to(xf86Info.vtno, "xf86OpenConsole");
if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
FatalError("xf86OpenConsole: VT_GETMODE failed %s\n",
@@ -289,16 +231,8 @@ xf86OpenConsole(void)
} else { /* serverGeneration != 1 */
if (!ShareVTs && VTSwitch)
{
- /*
- * now get the VT
- */
- if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) < 0)
- xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed %s\n",
- strerror(errno));
-
- if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) < 0)
- xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed %s\n",
- strerror(errno));
+ /* now get the VT */
+ switch_to(xf86Info.vtno, "xf86OpenConsole");
}
}
}
@@ -343,19 +277,11 @@ xf86CloseConsole(void)
* Perform a switch back to the active VT when we were started
*/
if (activeVT >= 0) {
- if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT) < 0)
- xf86Msg(X_WARNING, "xf86CloseConsole: VT_ACTIVATE failed: %s\n",
- strerror(errno));
- if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, activeVT) < 0)
- xf86Msg(X_WARNING,
- "xf86CloseConsole: VT_WAITACTIVE failed: %s\n",
- strerror(errno));
+ switch_to(activeVT, "xf86CloseConsole");
activeVT = -1;
}
}
close(xf86Info.consoleFd); /* make the vt-manager happy */
-
- restoreVtPerms(); /* restore the permissions */
}
int
@@ -382,10 +308,10 @@ xf86ProcessArgument(int argc, char *argv[], int i)
}
if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
{
- if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
+ if (sscanf(argv[i], "vt%2d", &xf86Info.vtno) == 0)
{
UseMsg();
- VTnum = -1;
+ xf86Info.vtno = -1;
return 0;
}
return 1;