1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
--- daemon/getvt.c.orig Tue Jan 6 14:56:39 2004
+++ daemon/getvt.c Wed Jun 23 17:13:16 2004
@@ -19,15 +19,42 @@
extern int GdmFirstVT;
extern gboolean GdmVTAllocation;
-#ifdef __linux__
+#if defined (__linux__) || defined (__FreeBSD__)
+#ifdef __linux__
#include <sys/vt.h>
+#endif
+#ifdef __FreeBSD__
+#include <sys/consio.h>
+#endif
+
+#ifdef __FreeBSD__
+static const char*
+__itovty(int val)
+{
+ static char str[8];
+ char* next = str + sizeof (str) - 1;
+
+ *next = '\0';
+ do {
+ *--next = "0123456789abcdefghigklmnopqrstuv"[val % 32];
+ } while (val /= 32);
+
+ return next;
+}
+#endif
static int
open_vt (int vtno)
{
- char *vtname = g_strdup_printf ("/dev/tty%d", vtno);
+ char *vtname;
int fd;
+
+#if defined (__linux__)
+ vtname = g_strdup_printf ("/dev/tty%d", vtno);
+#elif defined (__FreeBSD__)
+ vtname = g_strdup_printf ("/dev/ttyv%s", __itovty(vtno - 1));
+#endif
do {
errno = 0;
fd = open (vtname, O_RDWR
@@ -76,7 +103,11 @@
to_close_vts = g_list_prepend (to_close_vts,
GINT_TO_POINTER (fdv));
+#if defined (__linux__)
if ((ioctl(fd, VT_OPENQRY, &vtno) < 0) || (vtno == -1)) {
+#elif defined (__FreeBSD__)
+ if (ioctl(fd, VT_OPENQRY, &vtno) == -1) {
+#endif
vtno = -1;
goto cleanup;
}
@@ -145,7 +176,11 @@
int
gdm_get_cur_vt (void)
{
+#if defined (__linux__)
struct vt_stat s;
+#elif defined (__FreeBSD__)
+ int vtno;
+#endif
int fd;
do {
@@ -158,7 +193,7 @@
} while G_UNLIKELY (errno == EINTR);
if (fd < 0)
return -1;
-
+#if defined (__linux__)
ioctl (fd, VT_GETSTATE, &s);
VE_IGNORE_EINTR (close (fd));
@@ -167,6 +202,19 @@
printf ("current_Active %d\n", (int)s.v_active);
return s.v_active;
+#elif defined (__FreeBSD__)
+ if (ioctl (fd, VT_GETACTIVE, &vtno) == -1) {
+ VE_IGNORE_EINTR (close (fd));
+ return -1;
+ }
+
+ VE_IGNORE_EINTR (close (fd));
+
+ /* debug */
+ printf ("current_Active %d\n", vtno);
+
+ return vtno;
+#endif
}
#else /* here this is just a stub, we don't know how to do this outside
|