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>
37 #include "xf86_OSlib.h"
39 static int VTnum
= -1;
47 MessageType from
= X_PROBED
;
49 if (serverGeneration
== 1)
51 /* check if we're run with euid==0 */
54 FatalError("xf86OpenConsole: Server must be suid root\n");
58 * setup the virtual terminal manager
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...)
69 xf86Info
.vtno
= VTnum
;
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)
82 "xf86OpenConsole: Cannot open /dev/atc0 (%s)\n",
85 if ((ioctl(fd
, VT_OPENQRY
, &xf86Info
.vtno
) < 0) ||
86 (xf86Info
.vtno
== -1))
88 FatalError("xf86OpenConsole: Cannot find a free VT\n");
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)
102 "xf86OpenConsole: Cannot open %s (%s)\n",
103 vtname1
, strerror(errno
));
105 /* change ownership of the vt */
106 chown(vtname1
, getuid(), getgid());
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
;
126 if (ioctl(xf86Info
.consoleFd
, VT_SETMODE
, &VT
) < 0)
128 FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n");
133 /* serverGeneration != 1 */
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
)
158 ioctl(xf86Info
.consoleFd
, VT_ACTIVATE
, xf86Info
.vtno
);
159 ioctl(xf86Info
.consoleFd
, VT_WAITACTIVE
, 0);
161 if (ioctl(xf86Info
.consoleFd
, VT_GETMODE
, &VT
) != -1)
164 ioctl(xf86Info
.consoleFd
, VT_SETMODE
, &VT
); /* set dflt vt handling */
166 close(xf86Info
.consoleFd
); /* make the vt-manager happy */
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)
189 ErrorF("vtXX use the specified VT number\n");