First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / os-support / lynxos / lynx_init.c
blob03f72ca199f9cca8b8cb2cebc1198c4b89c0eb45
1 /*
2 * Copyright 1993 by Thomas Mueller
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Thomas Mueller not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Thomas Mueller makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
14 * THOMAS MUELLER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THOMAS MUELLER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
26 #ifdef HAVE_XORG_CONFIG_H
27 #include <xorg-config.h>
28 #endif
30 #include <X11/X.h>
31 #include <X11/Xmd.h>
33 #include "compiler.h"
35 #include "xf86.h"
36 #include "xf86Priv.h"
37 #include "xf86_OSlib.h"
39 static int VTnum = -1;
41 void
42 xf86OpenConsole()
44 struct vt_mode VT;
45 char vtname1[11];
46 int fd, pgrp;
47 MessageType from = X_PROBED;
49 if (serverGeneration == 1)
51 /* check if we're run with euid==0 */
52 if (geteuid() != 0)
54 FatalError("xf86OpenConsole: Server must be suid root\n");
58 * setup the virtual terminal manager
59 * NOTE:
60 * We use the out-of-the-box atc terminal driver,
61 * not the GE contributed vdt driver.
62 * Also, we do setup signals for VT switching which
63 * is not really necessary because we don't feed the
64 * VT switch keystrokes to the kernel in xf86Events.c
65 * (it bombs occasionally...)
67 if (VTnum != -1)
69 xf86Info.vtno = VTnum;
70 from = X_CMDLINE;
72 else
74 /* We could use /dev/con which is usually a symlink
75 * to /dev/atc0 but one could configure the system
76 * to use a serial line as console device, so to
77 * be sure we take /dev/atc0.
79 if ((fd = open("/dev/atc0",O_WRONLY,0)) < 0)
81 FatalError(
82 "xf86OpenConsole: Cannot open /dev/atc0 (%s)\n",
83 strerror(errno));
85 if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) ||
86 (xf86Info.vtno == -1))
88 FatalError("xf86OpenConsole: Cannot find a free VT\n");
90 close(fd);
92 xf86Msg(from, "using VT number %d\n", xf86Info.vtno);
94 sprintf(vtname1,"/dev/atc%d",xf86Info.vtno);
96 pgrp = getpgrp(); /* POSIX version ! */
97 ioctl(xf86Info.consoleFd, TIOCSPGRP, &pgrp);
99 if ((xf86Info.consoleFd = open(vtname1,O_RDWR|O_NDELAY,0)) < 0)
101 FatalError(
102 "xf86OpenConsole: Cannot open %s (%s)\n",
103 vtname1, strerror(errno));
105 /* change ownership of the vt */
106 chown(vtname1, getuid(), getgid());
109 * now get the VT
111 if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
113 xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
115 if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0)
117 FatalError("xf86OpenConsole: VT_GETMODE failed\n");
120 /* for future use... */
121 signal(SIGUSR1, xf86VTRequest);
123 VT.mode = VT_PROCESS;
124 VT.relsig = SIGUSR1;
125 VT.acqsig = SIGUSR1;
126 if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0)
128 FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n");
131 else
133 /* serverGeneration != 1 */
135 * now get the VT
137 if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0)
139 xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n");
142 * If the server doesn't have the VT when the reset occurs,
143 * this is to make sure we don't continue until the activate
144 * signal is received.
146 if (!xf86Screens[0]->vtSema)
147 sleep(5);
149 return;
152 void
153 xf86CloseConsole()
155 struct vt_mode VT;
157 #if 0
158 ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno);
159 ioctl(xf86Info.consoleFd, VT_WAITACTIVE, 0);
160 #endif
161 if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1)
163 VT.mode = VT_AUTO;
164 ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* set dflt vt handling */
166 close(xf86Info.consoleFd); /* make the vt-manager happy */
167 return;
171 xf86ProcessArgument(int argc, char *argv[], int i)
173 if ((argv[i][0] == 'v') && (argv[i][1] == 't'))
175 if (sscanf(argv[i], "vt%2d", &VTnum) == 0)
177 UseMsg();
178 VTnum = -1;
179 return(0);
181 return(1);
183 return(0);
186 void
187 xf86UseMsg()
189 ErrorF("vtXX use the specified VT number\n");
190 return;