2003-11-14 16:54:54 +01:00
|
|
|
/*
|
|
|
|
* Copyright 1992 by Rich Murphey <Rich@Rice.edu>
|
|
|
|
* 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 Rich Murphey and David Wexelblat
|
|
|
|
* not be used in advertising or publicity pertaining to distribution of
|
|
|
|
* the software without specific, written prior permission. Rich Murphey 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.
|
|
|
|
*
|
|
|
|
* RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO
|
|
|
|
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS, IN NO EVENT SHALL RICH MURPHEY 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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>
|
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"
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
#include <sys/utsname.h>
|
2005-10-03 18:46:14 +02:00
|
|
|
#include <sys/ioctl.h>
|
2003-11-14 17:49:22 +01:00
|
|
|
#include <stdlib.h>
|
2005-10-03 18:46:14 +02:00
|
|
|
#include <errno.h>
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
static Bool KeepTty = FALSE;
|
2011-08-26 17:42:41 +02:00
|
|
|
|
|
|
|
#ifdef PCCONS_SUPPORT
|
2003-11-14 16:54:54 +01:00
|
|
|
static int devConsoleFd = -1;
|
2011-08-26 17:42:41 +02:00
|
|
|
#endif
|
2003-11-25 20:29:01 +01:00
|
|
|
#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
|
2003-11-14 16:54:54 +01:00
|
|
|
static int VTnum = -1;
|
|
|
|
static int initialVT = -1;
|
2003-11-25 20:29:01 +01:00
|
|
|
#endif
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
#ifdef PCCONS_SUPPORT
|
|
|
|
/* Stock 0.1 386bsd pccons console driver interface */
|
2010-11-30 17:17:19 +01:00
|
|
|
#define PCCONS_CONSOLE_DEV1 "/dev/ttyv0"
|
2003-11-14 16:54:54 +01:00
|
|
|
#define PCCONS_CONSOLE_DEV2 "/dev/vga"
|
|
|
|
#define PCCONS_CONSOLE_MODE O_RDWR|O_NDELAY
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SYSCONS_SUPPORT
|
|
|
|
/* The FreeBSD 1.1 version syscons driver uses /dev/ttyv0 */
|
|
|
|
#define SYSCONS_CONSOLE_DEV1 "/dev/ttyv0"
|
|
|
|
#define SYSCONS_CONSOLE_DEV2 "/dev/vga"
|
|
|
|
#define SYSCONS_CONSOLE_MODE O_RDWR|O_NDELAY
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PCVT_SUPPORT
|
|
|
|
/* Hellmuth Michaelis' pcvt driver */
|
|
|
|
#ifndef __OpenBSD__
|
|
|
|
# define PCVT_CONSOLE_DEV "/dev/ttyv0"
|
|
|
|
#else
|
|
|
|
# define PCVT_CONSOLE_DEV "/dev/ttyC0"
|
|
|
|
#endif
|
|
|
|
#define PCVT_CONSOLE_MODE O_RDWR|O_NDELAY
|
|
|
|
#endif
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
#if defined(WSCONS_SUPPORT) && defined(__NetBSD__)
|
|
|
|
/* NetBSD's new console driver */
|
|
|
|
#define WSCONS_PCVT_COMPAT_CONSOLE_DEV "/dev/ttyE0"
|
|
|
|
#endif
|
|
|
|
|
2005-10-03 18:46:14 +02:00
|
|
|
#ifdef __GLIBC__
|
|
|
|
#define setpgrp setpgid
|
|
|
|
#endif
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
#define CHECK_DRIVER_MSG \
|
|
|
|
"Check your kernel's console driver configuration and /dev entries"
|
|
|
|
|
|
|
|
static char *supported_drivers[] = {
|
|
|
|
#ifdef PCCONS_SUPPORT
|
|
|
|
"pccons (with X support)",
|
|
|
|
#endif
|
|
|
|
#ifdef SYSCONS_SUPPORT
|
|
|
|
"syscons",
|
|
|
|
#endif
|
|
|
|
#ifdef PCVT_SUPPORT
|
|
|
|
"pcvt",
|
|
|
|
#endif
|
2003-11-14 17:49:22 +01:00
|
|
|
#ifdef WSCONS_SUPPORT
|
|
|
|
"wscons",
|
|
|
|
#endif
|
2003-11-14 16:54:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions to probe for the existance of a supported console driver.
|
|
|
|
* Any function returns either a valid file descriptor (driver probed
|
|
|
|
* succesfully), -1 (driver not found), or uses FatalError() if the
|
|
|
|
* driver was found but proved to not support the required mode to run
|
|
|
|
* an X server.
|
|
|
|
*/
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
typedef int (*xf86ConsOpen_t)(void);
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
#ifdef PCCONS_SUPPORT
|
2003-11-14 17:49:22 +01:00
|
|
|
static int xf86OpenPccons(void);
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif /* PCCONS_SUPPORT */
|
|
|
|
|
|
|
|
#ifdef SYSCONS_SUPPORT
|
2003-11-14 17:49:22 +01:00
|
|
|
static int xf86OpenSyscons(void);
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif /* SYSCONS_SUPPORT */
|
|
|
|
|
|
|
|
#ifdef PCVT_SUPPORT
|
2003-11-14 17:49:22 +01:00
|
|
|
static int xf86OpenPcvt(void);
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif /* PCVT_SUPPORT */
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
#ifdef WSCONS_SUPPORT
|
|
|
|
static int xf86OpenWScons(void);
|
|
|
|
#endif
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
/*
|
|
|
|
* The sequence of the driver probes is important; start with the
|
|
|
|
* driver that is best distinguishable, and end with the most generic
|
|
|
|
* driver. (Otherwise, pcvt would also probe as syscons, and either
|
2003-11-14 17:49:22 +01:00
|
|
|
* pcvt or syscons might succesfully probe as pccons.)
|
2003-11-14 16:54:54 +01:00
|
|
|
*/
|
|
|
|
static xf86ConsOpen_t xf86ConsTab[] = {
|
|
|
|
#ifdef PCVT_SUPPORT
|
|
|
|
xf86OpenPcvt,
|
|
|
|
#endif
|
|
|
|
#ifdef SYSCONS_SUPPORT
|
|
|
|
xf86OpenSyscons,
|
|
|
|
#endif
|
|
|
|
#ifdef PCCONS_SUPPORT
|
|
|
|
xf86OpenPccons,
|
2003-11-14 17:49:22 +01:00
|
|
|
#endif
|
|
|
|
#ifdef WSCONS_SUPPORT
|
|
|
|
xf86OpenWScons,
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
|
|
|
(xf86ConsOpen_t)NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2003-11-14 16:54:54 +01:00
|
|
|
xf86OpenConsole()
|
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
int i, fd = -1;
|
2003-11-14 16:54:54 +01:00
|
|
|
xf86ConsOpen_t *driver;
|
|
|
|
#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
|
2003-11-25 20:29:01 +01:00
|
|
|
int result;
|
2008-05-23 23:00:40 +02:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2003-11-25 20:29:01 +01:00
|
|
|
struct utsname uts;
|
2007-08-16 18:23:28 +02:00
|
|
|
#endif
|
2003-11-14 16:54:54 +01:00
|
|
|
vtmode_t vtmode;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (serverGeneration == 1)
|
|
|
|
{
|
|
|
|
/* check if we are run with euid==0 */
|
|
|
|
if (geteuid() != 0)
|
|
|
|
{
|
2005-04-20 14:25:48 +02:00
|
|
|
FatalError("xf86OpenConsole: Server must be suid root");
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!KeepTty)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* detaching the controlling tty solves problems of kbd character
|
|
|
|
* loss. This is not interesting for CO driver, because it is
|
|
|
|
* exclusive.
|
|
|
|
*/
|
|
|
|
setpgrp(0, getpid());
|
|
|
|
if ((i = open("/dev/tty",O_RDWR)) >= 0)
|
|
|
|
{
|
|
|
|
ioctl(i,TIOCNOTTY,(char *)0);
|
|
|
|
close(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* detect which driver we are running on */
|
|
|
|
for (driver = xf86ConsTab; *driver; driver++)
|
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
if ((fd = (*driver)()) >= 0)
|
2003-11-14 16:54:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that a supported console driver was found */
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
char cons_drivers[80] = {0, };
|
|
|
|
for (i = 0; i < sizeof(supported_drivers) / sizeof(char *); i++)
|
|
|
|
{
|
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
strcat(cons_drivers, ", ");
|
|
|
|
}
|
|
|
|
strcat(cons_drivers, supported_drivers[i]);
|
|
|
|
}
|
|
|
|
FatalError(
|
2005-04-20 14:25:48 +02:00
|
|
|
"%s: No console driver found\n\tSupported drivers: %s\n\t%s",
|
2003-11-14 16:54:54 +01:00
|
|
|
"xf86OpenConsole", cons_drivers, CHECK_DRIVER_MSG);
|
|
|
|
}
|
|
|
|
xf86Info.consoleFd = fd;
|
|
|
|
|
|
|
|
switch (xf86Info.consType)
|
|
|
|
{
|
|
|
|
#ifdef PCCONS_SUPPORT
|
|
|
|
case PCCONS:
|
|
|
|
if (ioctl (xf86Info.consoleFd, CONSOLE_X_MODE_ON, 0) < 0)
|
|
|
|
{
|
2005-04-20 14:25:48 +02:00
|
|
|
FatalError("%s: CONSOLE_X_MODE_ON failed (%s)\n%s",
|
2003-11-14 16:54:54 +01:00
|
|
|
"xf86OpenConsole", strerror(errno),
|
|
|
|
CHECK_DRIVER_MSG);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Hack to prevent keyboard hanging when syslogd closes
|
|
|
|
* /dev/console
|
|
|
|
*/
|
|
|
|
if ((devConsoleFd = open("/dev/console", O_WRONLY,0)) < 0)
|
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86Msg(X_WARNING,
|
|
|
|
"xf86OpenConsole: couldn't open /dev/console (%s)\n",
|
|
|
|
strerror(errno));
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
|
|
|
|
case SYSCONS:
|
2003-11-14 17:49:22 +01:00
|
|
|
/* as of FreeBSD 2.2.8, syscons driver does not need the #1 vt
|
|
|
|
* switching anymore. Here we check for FreeBSD 3.1 and up.
|
|
|
|
* Add cases for other *BSD that behave the same.
|
|
|
|
*/
|
2005-10-03 18:46:14 +02:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2003-11-14 17:49:22 +01:00
|
|
|
uname (&uts);
|
2005-10-03 18:46:14 +02:00
|
|
|
i = atof(uts.release) * 100;
|
|
|
|
if (i >= 310) goto acquire_vt;
|
|
|
|
#endif
|
2003-11-14 17:49:22 +01:00
|
|
|
/* otherwise fall through */
|
2003-11-14 16:54:54 +01:00
|
|
|
case PCVT:
|
2007-08-16 18:23:28 +02:00
|
|
|
#if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 200000000))
|
2003-11-14 16:54:54 +01:00
|
|
|
/*
|
|
|
|
* First activate the #1 VT. This is a hack to allow a server
|
|
|
|
* to be started while another one is active. There should be
|
|
|
|
* a better way.
|
|
|
|
*/
|
|
|
|
if (initialVT != 1) {
|
|
|
|
|
|
|
|
if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 1) != 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
|
|
|
}
|
|
|
|
sleep(1);
|
|
|
|
}
|
2007-08-16 18:23:28 +02:00
|
|
|
#endif
|
2003-11-14 17:49:22 +01:00
|
|
|
acquire_vt:
|
2011-05-20 07:39:09 +02:00
|
|
|
if (!xf86Info.ShareVTs) {
|
2008-12-16 06:07:42 +01:00
|
|
|
/*
|
|
|
|
* now get the VT
|
|
|
|
*/
|
|
|
|
SYSCALL(result =
|
|
|
|
ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno));
|
|
|
|
if (result != 0)
|
|
|
|
{
|
|
|
|
xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
|
|
|
|
}
|
|
|
|
SYSCALL(result =
|
2003-11-14 17:49:22 +01:00
|
|
|
ioctl(xf86Info.consoleFd, VT_WAITACTIVE, xf86Info.vtno));
|
2008-12-16 06:07:42 +01:00
|
|
|
if (result != 0)
|
|
|
|
{
|
|
|
|
xf86Msg(X_WARNING, "xf86OpenConsole: VT_WAITACTIVE failed\n");
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2008-12-16 06:07:42 +01:00
|
|
|
signal(SIGUSR1, xf86VTRequest);
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2008-12-16 06:07:42 +01:00
|
|
|
vtmode.mode = VT_PROCESS;
|
|
|
|
vtmode.relsig = SIGUSR1;
|
|
|
|
vtmode.acqsig = SIGUSR1;
|
|
|
|
vtmode.frsig = SIGUSR1;
|
|
|
|
if (ioctl(xf86Info.consoleFd, VT_SETMODE, &vtmode) < 0)
|
|
|
|
{
|
|
|
|
FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed");
|
|
|
|
}
|
2011-08-26 22:02:36 +02:00
|
|
|
#if !defined(__OpenBSD__) && !defined(USE_DEV_IO) && !defined(USE_I386_IOPL)
|
2008-12-16 06:07:42 +01:00
|
|
|
if (ioctl(xf86Info.consoleFd, KDENABIO, 0) < 0)
|
|
|
|
{
|
|
|
|
FatalError("xf86OpenConsole: KDENABIO failed (%s)",
|
|
|
|
strerror(errno));
|
|
|
|
}
|
2011-08-26 22:02:36 +02:00
|
|
|
#endif
|
2008-12-16 06:07:42 +01:00
|
|
|
if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0)
|
|
|
|
{
|
|
|
|
FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed");
|
|
|
|
}
|
2011-05-20 07:39:09 +02:00
|
|
|
} else { /* xf86Info.ShareVTs */
|
2008-12-16 06:07:42 +01:00
|
|
|
close(xf86Info.consoleFd);
|
|
|
|
}
|
|
|
|
break;
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
|
2003-11-14 17:49:22 +01:00
|
|
|
#ifdef WSCONS_SUPPORT
|
|
|
|
case WSCONS:
|
2008-05-19 08:09:33 +02:00
|
|
|
/* Nothing to do */
|
2003-11-14 17:49:22 +01:00
|
|
|
break;
|
|
|
|
#endif
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* serverGeneration != 1 */
|
|
|
|
#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
|
2011-05-20 07:39:09 +02:00
|
|
|
if (!xf86Info.ShareVTs &&
|
|
|
|
(xf86Info.consType == SYSCONS || xf86Info.consType == PCVT))
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef PCCONS_SUPPORT
|
|
|
|
|
|
|
|
static int
|
|
|
|
xf86OpenPccons()
|
|
|
|
{
|
|
|
|
int fd = -1;
|
|
|
|
|
|
|
|
if ((fd = open(PCCONS_CONSOLE_DEV1, PCCONS_CONSOLE_MODE, 0))
|
|
|
|
>= 0 ||
|
|
|
|
(fd = open(PCCONS_CONSOLE_DEV2, PCCONS_CONSOLE_MODE, 0))
|
|
|
|
>= 0)
|
|
|
|
{
|
|
|
|
if (ioctl(fd, CONSOLE_X_MODE_OFF, 0) < 0)
|
|
|
|
{
|
|
|
|
FatalError(
|
2005-04-20 14:25:48 +02:00
|
|
|
"%s: CONSOLE_X_MODE_OFF failed (%s)\n%s\n%s",
|
2003-11-14 16:54:54 +01:00
|
|
|
"xf86OpenPccons",
|
|
|
|
strerror(errno),
|
|
|
|
"Was expecting pccons driver with X support",
|
|
|
|
CHECK_DRIVER_MSG);
|
|
|
|
}
|
|
|
|
xf86Info.consType = PCCONS;
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86Msg(X_PROBED, "Using pccons driver with X support\n");
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* PCCONS_SUPPORT */
|
|
|
|
|
|
|
|
#ifdef SYSCONS_SUPPORT
|
|
|
|
|
|
|
|
static int
|
|
|
|
xf86OpenSyscons()
|
|
|
|
{
|
|
|
|
int fd = -1;
|
|
|
|
vtmode_t vtmode;
|
|
|
|
char vtname[12];
|
|
|
|
long syscons_version;
|
2003-11-14 17:49:22 +01:00
|
|
|
MessageType from;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
/* Check for syscons */
|
|
|
|
if ((fd = open(SYSCONS_CONSOLE_DEV1, SYSCONS_CONSOLE_MODE, 0)) >= 0
|
|
|
|
|| (fd = open(SYSCONS_CONSOLE_DEV2, SYSCONS_CONSOLE_MODE, 0)) >= 0)
|
|
|
|
{
|
|
|
|
if (ioctl(fd, VT_GETMODE, &vtmode) >= 0)
|
|
|
|
{
|
|
|
|
/* Get syscons version */
|
|
|
|
if (ioctl(fd, CONS_GETVERS, &syscons_version) < 0)
|
|
|
|
{
|
|
|
|
syscons_version = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
xf86Info.vtno = VTnum;
|
2003-11-14 17:49:22 +01:00
|
|
|
from = X_CMDLINE;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
#ifdef VT_GETACTIVE
|
|
|
|
if (ioctl(fd, VT_GETACTIVE, &initialVT) < 0)
|
|
|
|
initialVT = -1;
|
|
|
|
#endif
|
2011-05-20 07:39:09 +02:00
|
|
|
if (xf86Info.ShareVTs)
|
2008-12-16 06:07:42 +01:00
|
|
|
xf86Info.vtno = initialVT;
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
if (xf86Info.vtno == -1)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* For old syscons versions (<0x100), VT_OPENQRY returns
|
|
|
|
* the current VT rather than the next free VT. In this
|
|
|
|
* case, the server gets started on the current VT instead
|
|
|
|
* of the next free VT.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* check for the fixed VT_OPENQRY */
|
|
|
|
if (syscons_version >= 0x100)
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
if (ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0)
|
|
|
|
{
|
|
|
|
/* No free VTs */
|
|
|
|
xf86Info.vtno = -1;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (xf86Info.vtno == -1)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* All VTs are in use. If initialVT was found, use it.
|
|
|
|
*/
|
|
|
|
if (initialVT != -1)
|
|
|
|
{
|
|
|
|
xf86Info.vtno = initialVT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (syscons_version >= 0x100)
|
|
|
|
{
|
2005-04-20 14:25:48 +02:00
|
|
|
FatalError("%s: Cannot find a free VT",
|
2003-11-14 16:54:54 +01:00
|
|
|
"xf86OpenSyscons");
|
|
|
|
}
|
|
|
|
/* Should no longer reach here */
|
2005-04-20 14:25:48 +02:00
|
|
|
FatalError("%s: %s %s\n\t%s %s",
|
2003-11-14 16:54:54 +01:00
|
|
|
"xf86OpenSyscons",
|
|
|
|
"syscons versions prior to 1.0 require",
|
|
|
|
"either the",
|
|
|
|
"server's stdin be a VT",
|
|
|
|
"or the use of the vtxx server option");
|
|
|
|
}
|
|
|
|
}
|
2003-11-14 17:49:22 +01:00
|
|
|
from = X_PROBED;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
sprintf(vtname, "/dev/ttyv%01x", xf86Info.vtno - 1);
|
|
|
|
if ((fd = open(vtname, SYSCONS_CONSOLE_MODE, 0)) < 0)
|
|
|
|
{
|
2005-04-20 14:25:48 +02:00
|
|
|
FatalError("xf86OpenSyscons: Cannot open %s (%s)",
|
2003-11-14 16:54:54 +01:00
|
|
|
vtname, strerror(errno));
|
|
|
|
}
|
|
|
|
if (ioctl(fd, VT_GETMODE, &vtmode) < 0)
|
|
|
|
{
|
2005-04-20 14:25:48 +02:00
|
|
|
FatalError("xf86OpenSyscons: VT_GETMODE failed");
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
xf86Info.consType = SYSCONS;
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86Msg(X_PROBED, "Using syscons driver with X support");
|
|
|
|
if (syscons_version >= 0x100)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2005-04-20 14:25:48 +02:00
|
|
|
xf86ErrorF(" (version %ld.%ld)\n", syscons_version >> 8,
|
2003-11-14 16:54:54 +01:00
|
|
|
syscons_version & 0xFF);
|
|
|
|
}
|
2003-11-14 17:49:22 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
xf86ErrorF(" (version 0.x)\n");
|
|
|
|
}
|
|
|
|
xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* VT_GETMODE failed, probably not syscons */
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SYSCONS_SUPPORT */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef PCVT_SUPPORT
|
|
|
|
|
|
|
|
static int
|
|
|
|
xf86OpenPcvt()
|
|
|
|
{
|
|
|
|
/* This looks much like syscons, since pcvt is API compatible */
|
|
|
|
int fd = -1;
|
|
|
|
vtmode_t vtmode;
|
2003-11-14 17:49:22 +01:00
|
|
|
char vtname[12], *vtprefix;
|
2003-11-14 16:54:54 +01:00
|
|
|
struct pcvtid pcvt_version;
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
#ifndef __OpenBSD__
|
|
|
|
vtprefix = "/dev/ttyv";
|
|
|
|
#else
|
|
|
|
vtprefix = "/dev/ttyC";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fd = open(PCVT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0);
|
|
|
|
#ifdef WSCONS_PCVT_COMPAT_CONSOLE_DEV
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
fd = open(WSCONS_PCVT_COMPAT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0);
|
|
|
|
vtprefix = "/dev/ttyE";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (fd >= 0)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
if (ioctl(fd, VGAPCVTID, &pcvt_version) >= 0)
|
|
|
|
{
|
|
|
|
if(ioctl(fd, VT_GETMODE, &vtmode) < 0)
|
|
|
|
{
|
2005-04-20 14:25:48 +02:00
|
|
|
FatalError("%s: VT_GETMODE failed\n%s%s\n%s",
|
2003-11-14 16:54:54 +01:00
|
|
|
"xf86OpenPcvt",
|
|
|
|
"Found pcvt driver but X11 seems to be",
|
|
|
|
" not supported.", CHECK_DRIVER_MSG);
|
|
|
|
}
|
|
|
|
|
|
|
|
xf86Info.vtno = VTnum;
|
|
|
|
|
|
|
|
if (ioctl(fd, VT_GETACTIVE, &initialVT) < 0)
|
|
|
|
initialVT = -1;
|
|
|
|
|
|
|
|
if (xf86Info.vtno == -1)
|
|
|
|
{
|
|
|
|
if (ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0)
|
|
|
|
{
|
|
|
|
/* No free VTs */
|
|
|
|
xf86Info.vtno = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xf86Info.vtno == -1)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* All VTs are in use. If initialVT was found, use it.
|
|
|
|
*/
|
|
|
|
if (initialVT != -1)
|
|
|
|
{
|
|
|
|
xf86Info.vtno = initialVT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-04-20 14:25:48 +02:00
|
|
|
FatalError("%s: Cannot find a free VT",
|
2003-11-14 16:54:54 +01:00
|
|
|
"xf86OpenPcvt");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
2003-11-14 17:49:22 +01:00
|
|
|
sprintf(vtname, "%s%01x", vtprefix, xf86Info.vtno - 1);
|
2003-11-14 16:54:54 +01:00
|
|
|
if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0)
|
|
|
|
{
|
2008-05-19 08:09:33 +02:00
|
|
|
ErrorF("xf86OpenPcvt: Cannot open %s (%s)",
|
2003-11-14 16:54:54 +01:00
|
|
|
vtname, strerror(errno));
|
2008-05-19 08:09:33 +02:00
|
|
|
xf86Info.vtno = initialVT;
|
|
|
|
sprintf(vtname, "%s%01x", vtprefix, xf86Info.vtno - 1);
|
|
|
|
if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) {
|
|
|
|
FatalError("xf86OpenPcvt: Cannot open %s (%s)",
|
|
|
|
vtname, strerror(errno));
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
if (ioctl(fd, VT_GETMODE, &vtmode) < 0)
|
|
|
|
{
|
2005-04-20 14:25:48 +02:00
|
|
|
FatalError("xf86OpenPcvt: VT_GETMODE failed");
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
xf86Info.consType = PCVT;
|
2003-11-14 17:49:22 +01:00
|
|
|
#ifdef WSCONS_SUPPORT
|
|
|
|
xf86Msg(X_PROBED,
|
2008-05-19 08:09:33 +02:00
|
|
|
"Using wscons driver on %s in pcvt compatibility mode "
|
|
|
|
"(version %d.%d)\n", vtname,
|
2003-11-14 17:49:22 +01:00
|
|
|
pcvt_version.rmajor, pcvt_version.rminor);
|
|
|
|
#else
|
|
|
|
xf86Msg(X_PROBED, "Using pcvt driver (version %d.%d)\n",
|
|
|
|
pcvt_version.rmajor, pcvt_version.rminor);
|
|
|
|
#endif
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Not pcvt */
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* PCVT_SUPPORT */
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
#ifdef WSCONS_SUPPORT
|
|
|
|
|
|
|
|
static int
|
|
|
|
xf86OpenWScons()
|
|
|
|
{
|
|
|
|
int fd = -1;
|
|
|
|
int mode = WSDISPLAYIO_MODE_MAPPED;
|
|
|
|
int i;
|
|
|
|
char ttyname[16];
|
|
|
|
|
|
|
|
/* XXX Is this ok? */
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
#if defined(__NetBSD__)
|
|
|
|
sprintf(ttyname, "/dev/ttyE%d", i);
|
|
|
|
#elif defined(__OpenBSD__)
|
2008-05-19 08:09:33 +02:00
|
|
|
sprintf(ttyname, "/dev/ttyC%x", i);
|
2003-11-14 17:49:22 +01:00
|
|
|
#endif
|
|
|
|
if ((fd = open(ttyname, 2)) != -1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (fd != -1) {
|
|
|
|
if (ioctl(fd, WSDISPLAYIO_SMODE, &mode) < 0) {
|
2005-04-20 14:25:48 +02:00
|
|
|
FatalError("%s: WSDISPLAYIO_MODE_MAPPED failed (%s)\n%s",
|
2003-11-14 17:49:22 +01:00
|
|
|
"xf86OpenConsole", strerror(errno),
|
|
|
|
CHECK_DRIVER_MSG);
|
|
|
|
}
|
|
|
|
xf86Info.consType = WSCONS;
|
|
|
|
xf86Msg(X_PROBED, "Using wscons driver\n");
|
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WSCONS_SUPPORT */
|
2003-11-14 16:54:54 +01:00
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2003-11-14 16:54:54 +01:00
|
|
|
xf86CloseConsole()
|
|
|
|
{
|
|
|
|
#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT)
|
|
|
|
struct vt_mode VT;
|
|
|
|
#endif
|
|
|
|
|
2011-05-20 07:39:09 +02:00
|
|
|
if (xf86Info.ShareVTs) return;
|
2008-12-16 06:07:42 +01:00
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
switch (xf86Info.consType)
|
|
|
|
{
|
|
|
|
#ifdef PCCONS_SUPPORT
|
|
|
|
case PCCONS:
|
|
|
|
ioctl (xf86Info.consoleFd, CONSOLE_X_MODE_OFF, 0);
|
|
|
|
break;
|
|
|
|
#endif /* PCCONS_SUPPORT */
|
|
|
|
#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
|
|
|
|
case SYSCONS:
|
|
|
|
case PCVT:
|
|
|
|
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); /* dflt vt handling */
|
|
|
|
}
|
2011-08-26 22:02:36 +02:00
|
|
|
#if !defined(__OpenBSD__) && !defined(USE_DEV_IO) && !defined(USE_I386_IOPL)
|
2003-11-14 16:54:54 +01:00
|
|
|
if (ioctl(xf86Info.consoleFd, KDDISABIO, 0) < 0)
|
|
|
|
{
|
2005-04-20 14:25:48 +02:00
|
|
|
xf86FatalError("xf86CloseConsole: KDDISABIO failed (%s)",
|
2003-11-14 16:54:54 +01:00
|
|
|
strerror(errno));
|
|
|
|
}
|
2003-11-14 17:49:22 +01:00
|
|
|
#endif
|
2003-11-14 16:54:54 +01:00
|
|
|
if (initialVT != -1)
|
|
|
|
ioctl(xf86Info.consoleFd, VT_ACTIVATE, initialVT);
|
|
|
|
break;
|
|
|
|
#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
|
2003-11-14 17:49:22 +01:00
|
|
|
#ifdef WSCONS_SUPPORT
|
|
|
|
case WSCONS:
|
|
|
|
{
|
|
|
|
int mode = WSDISPLAYIO_MODE_EMUL;
|
2011-08-26 14:54:01 +02:00
|
|
|
ioctl(xf86Info.consoleFd, WSDISPLAYIO_SMODE, &mode);
|
2003-11-14 17:49:22 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
close(xf86Info.consoleFd);
|
2011-08-26 17:42:41 +02:00
|
|
|
#ifdef PCCONS_SUPPORT
|
2003-11-14 16:54:54 +01:00
|
|
|
if (devConsoleFd >= 0)
|
|
|
|
close(devConsoleFd);
|
2011-08-26 17:42:41 +02:00
|
|
|
#endif
|
2003-11-14 16:54:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
int
|
2003-11-14 17:49:22 +01:00
|
|
|
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;
|
2010-06-06 16:18:40 +02:00
|
|
|
return 1;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
|
|
|
|
if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
|
|
|
|
{
|
|
|
|
if (sscanf(argv[i], "vt%2d", &VTnum) == 0 ||
|
|
|
|
VTnum < 1 || VTnum > 12)
|
|
|
|
{
|
|
|
|
UseMsg();
|
|
|
|
VTnum = -1;
|
2010-06-06 16:18:40 +02:00
|
|
|
return 0;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2010-06-06 16:18:40 +02:00
|
|
|
return 1;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
|
2010-06-06 16:18:40 +02:00
|
|
|
return 0;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2003-11-14 16:54:54 +01:00
|
|
|
xf86UseMsg()
|
|
|
|
{
|
|
|
|
#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
|
|
|
|
ErrorF("vtXX use the specified VT number (1-12)\n");
|
2008-12-16 06:07:42 +01:00
|
|
|
ErrorF("-sharevts share VTs with another X server\n");
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */
|
|
|
|
ErrorF("-keeptty ");
|
|
|
|
ErrorF("don't detach controlling tty (for debugging only)\n");
|
|
|
|
return;
|
|
|
|
}
|