2005-04-20 14:25:48 +02:00
|
|
|
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sysv/sysv_init.c,v 3.4.4.3 1998/07/18 17:53:57 dawes Exp $ */
|
2003-11-14 16:54:54 +01:00
|
|
|
/*
|
|
|
|
* Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
|
|
|
|
* Copyright 1993 by David Wexelblat <dwex@goblin.org>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* 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 Thomas Roell and David Wexelblat
|
|
|
|
* not be used in advertising or publicity pertaining to distribution of
|
|
|
|
* the software without specific, written prior permission. Thomas Roell and
|
|
|
|
* David Wexelblat makes no representations about the suitability of this
|
|
|
|
* software for any purpose. It is provided "as is" without express or
|
|
|
|
* implied warranty.
|
|
|
|
*
|
|
|
|
* THOMAS ROELL AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
|
|
|
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS, IN NO EVENT SHALL THOMAS ROELL 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.
|
|
|
|
*
|
|
|
|
*/
|
2003-11-14 17:49:22 +01:00
|
|
|
/* $XConsortium: sysv_init.c /main/4 1996/02/21 17:54:31 kaleb $ */
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2005-07-03 09:02:09 +02:00
|
|
|
#ifdef HAVE_XORG_CONFIG_H
|
|
|
|
#include <xorg-config.h>
|
|
|
|
#endif
|
|
|
|
|
2005-04-20 14:25:48 +02:00
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xmd.h>
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
#include "compiler.h"
|
|
|
|
|
|
|
|
#include "xf86.h"
|
2003-11-14 17:49:22 +01:00
|
|
|
#include "xf86Priv.h"
|
2003-11-14 16:54:54 +01:00
|
|
|
#include "xf86_OSlib.h"
|
|
|
|
|
|
|
|
static Bool KeepTty = FALSE;
|
|
|
|
#ifdef SVR4
|
|
|
|
static Bool Protect0 = FALSE;
|
|
|
|
#endif
|
|
|
|
static int VTnum = -1;
|
|
|
|
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
void
|
|
|
|
xf86OpenConsole()
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
struct vt_mode VT;
|
|
|
|
char vtname1[10],vtname2[10];
|
2003-11-14 17:49:22 +01:00
|
|
|
MessageType from = X_PROBED;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
if (serverGeneration == 1)
|
|
|
|
{
|
|
|
|
/* check if we're run with euid==0 */
|
|
|
|
if (geteuid() != 0)
|
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
FatalError("xf86OpenConsole: Server must be suid root\n");
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SVR4
|
|
|
|
/* Protect page 0 to help find NULL dereferencing */
|
|
|
|
/* mprotect() doesn't seem to work */
|
|
|
|
if (Protect0)
|
|
|
|
{
|
|
|
|
int fd = -1;
|
|
|
|
|
|
|
|
if ((fd = open("/dev/zero", O_RDONLY, 0)) < 0)
|
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86Msg(X_WARNING,
|
|
|
|
"xf86OpenConsole: cannot open /dev/zero (%s)\n",
|
|
|
|
strerror(errno));
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((int)mmap(0, 0x1000, PROT_NONE,
|
|
|
|
MAP_FIXED | MAP_SHARED, fd, 0) == -1)
|
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86Msg(X_WARNING,
|
|
|
|
"xf86OpenConsole: failed to protect page 0 (%s)\n",
|
|
|
|
strerror(errno));
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* setup the virtual terminal manager
|
|
|
|
*/
|
|
|
|
if (VTnum != -1)
|
|
|
|
{
|
|
|
|
xf86Info.vtno = VTnum;
|
2003-11-14 17:49:22 +01:00
|
|
|
from = X_CMDLINE;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((fd = open("/dev/console",O_WRONLY,0)) < 0)
|
|
|
|
{
|
|
|
|
FatalError(
|
|
|
|
"xf86OpenConsole: Cannot open /dev/console (%s)\n",
|
|
|
|
strerror(errno));
|
|
|
|
}
|
|
|
|
if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) ||
|
|
|
|
(xf86Info.vtno == -1))
|
|
|
|
{
|
|
|
|
FatalError("xf86OpenConsole: Cannot find a free VT\n");
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno);
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
sprintf(vtname1,"/dev/vc%02d",xf86Info.vtno); /* ESIX */
|
|
|
|
sprintf(vtname2,"/dev/vt%02d",xf86Info.vtno); /* rest of the world */
|
|
|
|
|
|
|
|
if (!KeepTty)
|
|
|
|
{
|
|
|
|
setpgrp();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((xf86Info.consoleFd = open(vtname1, O_RDWR|O_NDELAY, 0)) < 0) &&
|
|
|
|
((xf86Info.consoleFd = open(vtname2, O_RDWR|O_NDELAY, 0)) < 0))
|
|
|
|
{
|
|
|
|
FatalError("xf86OpenConsole: Cannot open %s (%s) (%s)\n",
|
|
|
|
vtname2, vtname1, strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* change ownership of the vt */
|
|
|
|
if (chown(vtname1, getuid(), getgid()) < 0)
|
|
|
|
{
|
|
|
|
chown(vtname2, getuid(), getgid());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* now get the VT
|
|
|
|
*/
|
|
|
|
if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
|
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
|
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n");
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
|
|
|
|
{
|
|
|
|
FatalError("xf86OpenConsole: VT_GETMODE failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
signal(SIGUSR1, xf86VTRequest);
|
|
|
|
|
|
|
|
VT.mode = VT_PROCESS;
|
|
|
|
VT.relsig = SIGUSR1;
|
|
|
|
VT.acqsig = SIGUSR1;
|
|
|
|
if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
|
|
|
|
{
|
|
|
|
FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n");
|
|
|
|
}
|
|
|
|
if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0)
|
|
|
|
{
|
|
|
|
FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* serverGeneration != 1 */
|
|
|
|
/*
|
|
|
|
* now get the VT
|
|
|
|
*/
|
|
|
|
if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
|
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
if (ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno) != 0)
|
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n");
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the server doesn't have the VT when the reset occurs,
|
|
|
|
* this is to make sure we don't continue until the activate
|
|
|
|
* signal is received.
|
|
|
|
*/
|
2003-11-14 17:49:22 +01:00
|
|
|
if (!xf86Screens[0]->vtSema)
|
2003-11-14 16:54:54 +01:00
|
|
|
sleep(5);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
void
|
|
|
|
xf86CloseConsole()
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
struct vt_mode VT;
|
|
|
|
|
|
|
|
#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 */
|
|
|
|
}
|
|
|
|
close(xf86Info.consoleFd); /* make the vt-manager happy */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
int
|
|
|
|
xf86ProcessArgument(int argc, char *argv[], int i)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Keep server from detaching from controlling tty. This is useful
|
|
|
|
* when debugging (so the server can receive keyboard signals.
|
|
|
|
*/
|
|
|
|
if (!strcmp(argv[i], "-keeptty"))
|
|
|
|
{
|
|
|
|
KeepTty = TRUE;
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
#ifdef SVR4
|
|
|
|
/*
|
|
|
|
* Undocumented flag to protect page 0 from read/write to help
|
|
|
|
* catch NULL pointer dereferences. This is purely a debugging
|
|
|
|
* flag.
|
|
|
|
*/
|
|
|
|
if (!strcmp(argv[i], "-protect0"))
|
|
|
|
{
|
|
|
|
Protect0 = TRUE;
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
|
|
|
|
{
|
|
|
|
if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
|
|
|
|
{
|
|
|
|
UseMsg();
|
|
|
|
VTnum = -1;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
void
|
|
|
|
xf86UseMsg()
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
ErrorF("vtXX use the specified VT number\n");
|
|
|
|
ErrorF("-keeptty ");
|
|
|
|
ErrorF("don't detach controlling tty (for debugging only)\n");
|
|
|
|
return;
|
|
|
|
}
|