summaryrefslogtreecommitdiff
path: root/hw/xfree86/os-support/linux/lnx_init.c
diff options
context:
space:
mode:
authorEgbert Eich <eich@suse.de>2005-01-14 18:42:26 +0000
committerEgbert Eich <eich@suse.de>2005-01-14 18:42:26 +0000
commit16f9d2d72a2378470e9c5b31c59fa6c9a00892d6 (patch)
treee1b79c5fec7e1b9c1c48dd92a0fd223e55f4f2b7 /hw/xfree86/os-support/linux/lnx_init.c
parent6c0b03a2362f33ae24a2f6845ed1418c9af4b8bc (diff)
Let the OS instead of X save/restore text console fonts on Linux. So far we
relied on the generic VGA layer to restore text console fonts for us when shutting down the server or VT switching back to the text console. This has worked rather well but it has some downsides on Linux: a. Many people use fbdev as console text mode. In this case it is not necessary to save/restore console fonts as the console is running in graphics mode anyway. b. Some architectures don't have a fbdev console but require a full POST of even the primary card (ie. IA64). This posting has to take place before we even have a chance to save anything. Therefore the fonts we save are the once written to the chip by POST, not what has been programmed by the user. c. Certain chipsets utilize the BIOS to perform mode setting. This may interfer with the vga save/restore font function in a strange way. It would therefore be preferrable to let the OS - which has been used to set up the font in the first place - take care of saving/restoring the data. I will attach a patch which will do so for Linux. To make this fully functional a small patch needs to be applied to the Linux kernel. To disable this feature add: #define DoOSFontRestore NO to your host.def. (Bugzilla #2277)
Diffstat (limited to 'hw/xfree86/os-support/linux/lnx_init.c')
-rw-r--r--hw/xfree86/os-support/linux/lnx_init.c94
1 files changed, 78 insertions, 16 deletions
diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c
index 0ac8c6a8b..b068af2d0 100644
--- a/hw/xfree86/os-support/linux/lnx_init.c
+++ b/hw/xfree86/os-support/linux/lnx_init.c
@@ -1,3 +1,4 @@
+/* $XdotOrg: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c,v 1.2 2004/04/23 19:54:08 eich Exp $ */
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/lnx_init.c,v 3.14 2001/10/31 22:50:30 tsi Exp $ */
/*
* Copyright 1992 by Orest Zborowski <obz@Kodak.com>
@@ -7,19 +8,19 @@
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
- * documentation, and that the names of Orest Zborowski and David Wexelblat
- * not be used in advertising or publicity pertaining to distribution of
+ * documentation, and that the names of Orest Zborowski and David Wexelblat
+ * not be used in advertising or publicity pertaining to distribution of
* the software without specific, written prior permission. Orest Zborowski
- * and David Wexelblat make no representations about the suitability of this
- * software for any purpose. It is provided "as is" without express or
+ * and David Wexelblat make no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
* implied warranty.
*
- * OREST ZBOROWSKI AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD
- * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID WEXELBLAT BE LIABLE
- * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OREST ZBOROWSKI AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD
+ * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID WEXELBLAT BE LIABLE
+ * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
@@ -35,6 +36,8 @@
#include "xf86_OSlib.h"
#include "lnx.h"
+#include <sys/stat.h>
+
#ifdef USE_DEV_FB
extern char *getenv(const char *);
#include <linux/fb.h>
@@ -45,13 +48,44 @@ static Bool KeepTty = FALSE;
static int VTnum = -1;
static int activeVT = -1;
+static int vtPermSave[4];
+static char vtname[11];
+
+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)
+{
+ /* Set the terminal permissions back to before we started. */
+ chown("/dev/tty0", vtPermSave[0], vtPermSave[1]);
+ chown(vtname, vtPermSave[2], vtPermSave[3]);
+}
+
void
xf86OpenConsole(void)
{
int i, fd = -1;
int result;
struct vt_mode VT;
- char vtname[11];
struct vt_stat vts;
MessageType from = X_PROBED;
#ifdef USE_DEV_FB
@@ -61,7 +95,7 @@ xf86OpenConsole(void)
char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL };
char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
- if (serverGeneration == 1)
+ if (serverGeneration == 1)
{
/* check if we're run with euid==0 */
if (geteuid() != 0)
@@ -124,6 +158,15 @@ xf86OpenConsole(void)
xf86Info.vtno, strerror(errno));
}
+ /*
+ * 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");
+ }
+
/* change ownership of the vt */
chown(vtname, getuid(), getgid());
@@ -170,8 +213,11 @@ xf86OpenConsole(void)
{
xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n");
}
+#if defined(DO_OS_FONTRESTORE)
+ lnx_savefont();
+#endif
SYSCALL(result = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT));
- if (result < 0)
+ if (result < 0)
{
FatalError("xf86OpenConsole: VT_GETMODE failed\n");
}
@@ -181,7 +227,7 @@ xf86OpenConsole(void)
VT.mode = VT_PROCESS;
VT.relsig = SIGUSR1;
VT.acqsig = SIGUSR1;
- if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
+ if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
{
FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n");
}
@@ -202,7 +248,7 @@ xf86OpenConsole(void)
close(fbfd);
#endif
}
- else
+ else
{
/* serverGeneration != 1 */
/*
@@ -227,17 +273,25 @@ void
xf86CloseConsole()
{
struct vt_mode VT;
+#if defined(DO_OS_FONTRESTORE)
+ struct vt_stat vts;
+ int vtno = -1;
+ if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts) == 0)
+ vtno = vts.v_active;
+#endif
#if 0
ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno);
ioctl(xf86Info.consoleFd, VT_WAITACTIVE, 0);
#endif
ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); /* Back to text mode ... */
+
if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1)
{
VT.mode = VT_AUTO;
ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* set dflt vt handling */
}
+
/*
* Perform a switch back to the active VT when we were started
*/
@@ -246,7 +300,15 @@ xf86CloseConsole()
ioctl(xf86Info.consoleFd, VT_ACTIVATE, activeVT);
activeVT = -1;
}
+#if defined(DO_OS_FONTRESTORE)
+ if (xf86Info.vtno == vtno)
+ lnx_restorefont();
+ lnx_freefontdata();
+#endif
close(xf86Info.consoleFd); /* make the vt-manager happy */
+
+ restoreVtPerms(); /* restore the permissions */
+
return;
}
@@ -254,7 +316,7 @@ int
xf86ProcessArgument(int argc, char *argv[], int i)
{
/*
- * Keep server from detaching from controlling tty. This is useful
+ * Keep server from detaching from controlling tty. This is useful
* when debugging (so the server can receive keyboard signals.
*/
if (!strcmp(argv[i], "-keeptty"))