#include "X.h"
#include "Xmd.h"
#include "input.h"
#include "scrnintstr.h"
#include "compiler.h"
#include <sys/param.h>
#include "xf86.h"
#include "xf86Priv.h"
#include "xf86_OSlib.h"
extern Bool RunFromSmartParent;
static Bool KeepTty = FALSE;
#if BSD >= 199306
static void
NonBlockConsoleOff()
{
register int i;
i = fcntl(2, F_GETFL, 0);
if (i >= 0)
(void) fcntl(2, F_SETFL, i & ~FNDELAY);
}
#endif
void
xf86OpenConsole()
{
int i, fd;
if (serverGeneration == 1)
{
if (geteuid() != 0)
{
FatalError("xf86OpenConsole: Server must be suid root\n");
}
if (!KeepTty)
{
#if BSD >= 199306
if (RunFromSmartParent) {
if (atexit(NonBlockConsoleOff))
xf86Msg(X_WARNING,
"InitOutput: can't register NBIO exit handler\n");
i = fcntl(2, F_GETFL, 0);
if (i >= 0)
i = fcntl(2, F_SETFL, i | FNDELAY);
if (i < 0)
xf86Msg(X_WARNING,
"InitOutput: can't put stderr in non-block mode\n");
}
#else
setpgrp(0, getpid());
if ((i = open("/dev/tty",O_RDWR)) >= 0)
{
ioctl(i,TIOCNOTTY,(char *)0);
close(i);
}
#endif
}
if ((xf86Info.consoleFd = open("/dev/kbd", O_RDWR|O_NDELAY,0)) < 0)
{
FatalError("xf86OpenConsole: Cannot open /dev/kbd (%s)\n",
strerror(errno));
}
if ((xf86Info.screenFd = open("/dev/vga", O_RDWR|O_NDELAY,0)) < 0)
{
FatalError("xf86OpenConsole: Cannot open /dev/vga (%s)\n",
strerror(errno));
}
if (ioctl(xf86Info.consoleFd, PCCONIOCRAW, 0) < 0)
{
FatalError("%s: PCCONIOCRAW failed (%s)\n",
"xf86OpenConsole", strerror(errno));
}
}
return;
}
void
xf86CloseConsole()
{
ioctl (xf86Info.consoleFd, PCCONIOCCOOK, 0);
if (xf86Info.screenFd != xf86Info.consoleFd)
{
close(xf86Info.screenFd);
}
close(xf86Info.consoleFd);
return;
}
int
xf86ProcessArgument (int argc, char *argv[], int i)
{
if (!strcmp(argv[i], "-keeptty"))
{
KeepTty = TRUE;
return(1);
}
return(0);
}
void
xf86UseMsg()
{
ErrorF("-keeptty ");
ErrorF("don't detach controlling tty (for debugging only)\n");
return;
}