29
29
#include <sys/stat.h>
30
30
#include <sys/types.h>
33
#include <X11/Xatom.h>
35
#include "gdmconfig.h"
37
/* Virtual terminals only supported on Linux, FreeBSD, or DragonFly */
39
#if defined (__linux__) || defined (__FreeBSD__) || defined (__DragonFly__)
41
#if defined (__linux__)
40
#include "gdm-common.h"
41
#include "gdm-daemon-config.h"
45
* Get the VT number associated with the display via the XFree86_VT
49
gdm_get_current_vtnum (Display *display)
55
unsigned long bytes_after;
62
prop = XInternAtom (display, "XFree86_VT", True);
64
gdm_debug ("no XFree86_VT atom\n");
67
if (XGetWindowProperty (display, DefaultRootWindow (display), prop, 0, 1,
68
False, AnyPropertyType, &actualtype, &actualformat,
69
&nitems, &bytes_after, &buf)) {
70
gdm_debug ("no XFree86_VT property\n");
74
gdm_debug ("%lu items in XFree86_VT property!\n", nitems);
83
switch (actualformat) {
85
num = (*(uint8_t *)(void *)buf);
88
num = (*(uint16_t *)(void *)buf);
91
num = (*(uint32_t *)(void *)buf);
94
gdm_debug ("format %d in XFree86_VT property!\n", actualformat);
100
gdm_debug ("type %lx in XFree86_VT property!\n", actualtype);
108
#if defined (GDM_USE_SYS_VT)
42
109
#include <sys/vt.h>
43
#elif defined (__FreeBSD__) || defined (__DragonFly__)
110
#elif defined (GDM_USE_CONSIO_VT)
44
111
#include <sys/consio.h>
46
113
static const char*
130
gdm_get_vt_device (int vtno)
132
gchar *vtname = NULL;
134
#if defined (GDM_USE_SYS_VT)
136
vtname = g_strdup_printf ("/dev/vt/%d", vtno);
138
vtname = g_strdup_printf ("/dev/tty%d", vtno);
140
#elif defined (GDM_USE_CONSIO_VT)
141
vtname = g_strdup_printf ("/dev/ttyv%s", __itovty (vtno - 1));
147
#if defined (GDM_USE_SYS_VT) || defined (GDM_USE_CONSIO_VT)
150
#define GDMCONSOLEDEVICE "/dev/vt/0"
152
#define GDMCONSOLEDEVICE "/dev/console"
62
157
open_vt (int vtno)
67
#if defined (__linux__)
68
vtname = g_strdup_printf ("/dev/tty%d", vtno);
69
#elif defined (__FreeBSD__) || defined (__DragonFly__)
70
vtname = g_strdup_printf ("/dev/ttyv%s", __itovty (vtno - 1));
162
vtname = gdm_get_vt_device (vtno);
74
166
fd = open (vtname, O_RDWR
112
for (vtno = gdm_get_value_int (GDM_KEY_FIRST_VT), vtmask = 1 << vtno;
207
for (vtno = gdm_daemon_config_get_value_int (GDM_KEY_FIRST_VT), vtmask = 1 << vtno;
113
208
vtstat.v_state & vtmask; vtno++, vtmask <<= 1);
115
210
VE_IGNORE_EINTR (close (fd));
195
291
gdm_get_empty_vt_argument (int *fd, int *vt)
197
if ( ! gdm_get_value_bool (GDM_KEY_VT_ALLOCATION)) {
293
if ( ! gdm_daemon_config_get_value_bool (GDM_KEY_VT_ALLOCATION)) {
202
#if defined (__linux__)
203
*vt = get_free_vt_linux (fd);
204
#elif defined (__FreeBSD__) || defined (__DragonFly__)
205
*vt = get_free_vt_freebsd_dragonfly (fd);
298
#if defined (GDM_USE_SYS_VT)
299
*vt = get_free_vt_sys (fd);
300
#elif defined (GDM_USE_CONSIO_VT)
301
*vt = get_free_vt_consio (fd);
233
ioctl (fd, VT_ACTIVATE, vt);
234
ioctl (fd, VT_WAITACTIVE, vt);
331
rc = ioctl (fd, VT_ACTIVATE, vt);
332
rc = ioctl (fd, VT_WAITACTIVE, vt);
236
334
VE_IGNORE_EINTR (close (fd));
240
gdm_get_cur_vt (void)
338
gdm_get_current_vt (void)
242
#if defined (__linux__)
340
#if defined (GDM_USE_SYS_VT)
243
341
struct vt_stat s;
244
#elif defined (__FreeBSD__) || defined (__DragonFly__)
342
#elif defined (GDM_USE_CONSIO_VT)
251
fd = open ("/dev/console", O_WRONLY
349
fd = open (GDMCONSOLEDEVICE,
256
355
} while G_UNLIKELY (errno == EINTR);
259
#if defined (__linux__)
358
#if defined (GDM_USE_SYS_VT)
260
359
ioctl (fd, VT_GETSTATE, &s);
262
361
VE_IGNORE_EINTR (close (fd));
269
368
return s.v_active;
270
#elif defined (__FreeBSD__) || defined (__DragonFly__)
369
#elif defined (GDM_USE_CONSIO_VT)
271
370
if (ioctl (fd, VT_GETACTIVE, &vtno) == -1) {
272
371
VE_IGNORE_EINTR (close (fd));
276
VE_IGNORE_EINTR (close (fd));
375
VE_IGNORE_EINTR (close (fd));
287
#else /* here this is just a stub, we don't know how to do this outside
386
#else /* GDM_USE_SYS_VT || GDM_USE_CONSIO_VT - Here this is just
387
* a stub, we do not know how to support this on other
291
392
gdm_get_empty_vt_argument (int *fd, int *vt)