Package: kde-workspace / 4:4.11.13-2

kdm_vt_switching_on_kfreebsd.diff Patch series | download
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
From: Modestas Vainius <modax@debian.org>
Subject: implement VT switching and status detection support in KDM on kFreeBSD
Forwarded: no
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=586540
Last-Update: 2011-08-11

This patch implements proper VT switching for KDM on kFreeBSD. It also includes
detection of the next available VT which should prevent KDM from taking over
vt2 on bootup and locking up keyboard/mouse input.

This revision of the patch is pretty hackish. What is more, it does not cover
FreeBSD (only kFreeBSD) while it could perfectly do so.
Index: kde-workspace/kdm/backend/dm.c
===================================================================
--- kde-workspace.orig/kdm/backend/dm.c	2014-05-07 20:21:11.614072291 +0200
+++ kde-workspace/kdm/backend/dm.c	2014-05-07 20:21:11.610072455 +0200
@@ -47,7 +47,13 @@
 
 #ifdef HAVE_VTS
 # include <sys/ioctl.h>
+#if defined(__linux__)
 # include <sys/vt.h>
+#elif defined(__FreeBSD_kernel__)
+# include <sys/consio.h>
+# include <sys/tty.h>
+# include <sys/sysctl.h>
+#endif
 #endif
 
 static void sigHandler(int n);
@@ -357,7 +363,12 @@
 int
 TTYtoVT(const char *tty)
 {
-    return memcmp(tty, "tty", 3) ? 0 : atoi(tty + 3);
+    if (!memcmp(tty, "ttyv", 4)) /* FreeBSD, tty no is in hex */
+        return (int) strtoul(tty+4, NULL, 16);
+    else if (!memcmp(tty, "tty", 3)) /* Linux */
+        return atoi(tty + 3);
+    else
+        return 0;
 }
 
 int
@@ -1062,9 +1073,15 @@
                     } else {
                         int con = open("/dev/console", O_RDONLY);
                         if (con >= 0) {
+                            int activevt;
+#if defined(__linux__)
                             struct vt_stat vtstat;
                             ioctl(con, VT_GETSTATE, &vtstat);
-                            if (vtstat.v_active == d->serverVT) {
+                            activevt = vtstat.v_active;
+#elif defined(__FreeBSD_kernel__)
+                            ioctl(con, VT_GETACTIVE, &activevt);
+#endif
+                            if (activevt == d->serverVT) {
                                 int vt = 1;
                                 struct display *di;
                                 for (di = displays; di; di = di->next)
@@ -1077,7 +1094,9 @@
                                         vt = di->serverVT;
                                 ioctl(con, VT_ACTIVATE, vt);
                             }
+#ifdef __linux__
                             ioctl(con, VT_DISALLOCATE, d->serverVT);
+#endif
                             close(con);
                         }
                     }
@@ -1350,16 +1369,41 @@
 static int
 getBusyVTs(void)
 {
-    struct vt_stat vtstat;
-    int con;
-
     if (activeVTs == -1) {
+#if defined(__linux__)
+        struct vt_stat vtstat;
+        int con;
+
         vtstat.v_state = 0;
         if ((con = open("/dev/console", O_RDONLY)) >= 0) {
             ioctl(con, VT_GETSTATE, &vtstat);
             close(con);
         }
         activeVTs = vtstat.v_state;
+#elif defined(__FreeBSD_kernel__)
+        struct xtty *ttys;
+        size_t s, i, firstvt;
+        struct stat st;
+
+        activeVTs = 0;
+        firstvt = ~0;
+        /* We need rdev of the first tty */
+        if (stat("/dev/ttyv0", &st))
+            firstvt = 0; /* If stat fails, 0 should be safe default */
+
+        if (!sysctlbyname("kern.ttys", NULL, &s, NULL, 0)) {
+            ttys = (struct xtty *) malloc(s);
+            sysctlbyname("kern.ttys", ttys, &s, NULL, 0);
+            for (i = 0; (i < s / sizeof(struct xtty)) &&
+                (i < sizeof(activeVTs) * 8); i++)
+            {
+                if (firstvt == ~0 && st.st_rdev == ttys[i].xt_dev)
+                    firstvt = i;
+                if (i >= firstvt)
+                    activeVTs |= !!(ttys[i].xt_flags & TF_OPENED) << (i - firstvt);
+            }
+        }
+#endif
     }
     return activeVTs;
 }
Index: kde-workspace/kdm/backend/greet.h
===================================================================
--- kde-workspace.orig/kdm/backend/greet.h	2014-05-07 20:21:11.614072291 +0200
+++ kde-workspace/kdm/backend/greet.h	2014-05-07 20:21:11.610072455 +0200
@@ -53,7 +53,7 @@
 # define USE_SYSLOG
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD_kernel__)
 /* This needs to be run-time configurable, additionally. */
 # define HAVE_VTS
 #endif
Index: kde-workspace/kdm/backend/client.c
===================================================================
--- kde-workspace.orig/kdm/backend/client.c	2014-05-07 20:21:11.614072291 +0200
+++ kde-workspace/kdm/backend/client.c	2014-05-07 20:21:11.610072455 +0200
@@ -1352,7 +1352,11 @@
     
 # ifdef HAVE_VTS
     if (td->serverVT > 0)
+# if defined(__linux__)
         sprintf(ckDeviceBuf, "/dev/tty%d", td->serverVT);
+# elif defined(__FreeBSD_kernel__)
+        sprintf(ckDeviceBuf, "/dev/ttyv%x", td->serverVT);
+# endif
 # endif
     isLocal = ((td->displayType & d_location) == dLocal);
 # ifdef XDMCP
Index: kde-workspace/kdm/kfrontend/genkdmconf.c
===================================================================
--- kde-workspace.orig/kdm/kfrontend/genkdmconf.c	2014-05-07 20:21:11.614072291 +0200
+++ kde-workspace/kdm/kfrontend/genkdmconf.c	2014-05-07 20:21:11.610072455 +0200
@@ -1547,7 +1547,8 @@
 upd_servervts(Entry *ce, Section *cs ATTR_UNUSED)
 {
     if (!ce->active) { /* there is only the Global one */
-#ifdef __linux__ /* XXX actually, sysvinit */
+/* XXX actually, sysvinit */
+#if defined(__linux__) || defined(__FreeBSD_kernel__)
         getInitTab();
         ASPrintf((char **)&ce->value, "-%d", maxTTY + 1);
         ce->active = ce->written = True;
@@ -1559,14 +1560,19 @@
 upd_consolettys(Entry *ce, Section *cs ATTR_UNUSED)
 {
     if (!ce->active) { /* there is only the Global one */
-#ifdef __linux__ /* XXX actually, sysvinit */
+/* XXX actually, sysvinit */
+#if defined(__linux__) || defined(__FreeBSD_kernel__)
         char *buf;
         int i;
 
         getInitTab();
         for (i = 0, buf = 0; i < 16; i++)
             if (TTYmask & (1 << i))
+#if defined(__linux__)
                 strCat(&buf, ",tty%d", i + 1);
+#elif defined(__FreeBSD_kernel__)
+                strCat(&buf, ",ttyv%x", i);
+#endif
         if (buf) {
             ce->value = buf + 1;
             ce->active = ce->written = True;
@@ -3198,7 +3204,7 @@
             }
         }
     }
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD_kernel__)
     if (!stat("/etc/debian_version", &st)) { /* debian */
         defminuid = "1000";
         defmaxuid = "29999";
Index: kde-workspace/kdm/config.def
===================================================================
--- kde-workspace.orig/kdm/config.def	2014-05-07 20:21:11.614072291 +0200
+++ kde-workspace/kdm/config.def	2014-05-07 20:21:11.610072455 +0200
@@ -873,7 +873,7 @@
  This option is for operating systems (<acronym>OS</acronym>s) with support
  for virtual terminals (<acronym>VT</acronym>s), by both &kdm; and the
  <acronym>OS</acronym>s itself.
- Currently this applies only to Linux.
+ Currently this applies only to Linux and kFreeBSD.
  </para><para>
  When &kdm; switches to console mode, it starts monitoring all
  <acronym>TTY</acronym> lines listed here (without the leading
Index: kde-workspace/kdm/backend/util.c
===================================================================
--- kde-workspace.orig/kdm/backend/util.c	2014-05-07 20:21:11.614072291 +0200
+++ kde-workspace/kdm/backend/util.c	2014-05-07 20:21:11.614072291 +0200
@@ -54,6 +54,15 @@
 # include <sys/utsname.h>
 #endif
 
+#ifdef HAVE_VTS
+#  include <sys/ioctl.h>
+#  if defined(__linux__)
+#    include <linux/vt.h>
+#  elif defined(__FreeBSD_kernel__)
+#    include <sys/consio.h>
+#  endif
+#endif
+
 void *
 Calloc(size_t nmemb, size_t size)
 {
@@ -663,6 +672,29 @@
 
 #undef atox
 
+#ifdef HAVE_VTS
+/* Get next free VT. Works only on virtual terminal devices */
+static int
+getNextFreeVT(const char *tty)
+{
+    int fd, vt;
+    char *dev;
+
+    vt = -1;
+    dev = (char*) Malloc(strlen(tty) + 6);
+    sprintf(dev, "/dev/%s", tty);
+
+    fd = open(dev, O_RDONLY);
+    if (fd >= 0) {
+        if (ioctl(fd, VT_OPENQRY, &vt))
+            vt = -1;
+        close(fd);
+    }
+    free(dev);
+    return vt;
+}
+#endif
+
 /* X -from ip6-addr does not work here, so i don't know whether this is needed.
 #define IP6_MAGIC
 */
@@ -682,6 +714,10 @@
 #else
     STRUCTUTMP *ut;
 #endif
+#ifdef HAVE_VTS
+    int con_fvt;
+    con_fvt = -2;
+#endif
 
     for (di = displays; di; di = di->next)
         if (((flags & lstRemote) || (di->displayType & d_location) == dLocal) &&
@@ -713,11 +749,19 @@
                 if (!(flags & lstRemote))
                     continue;
             } else {
+                if (!*ut->ut_line)
+                    continue;
                 /* hack around broken konsole which does not set ut_host. */
+#ifdef HAVE_VTS
+                if (con_fvt == -2)
+                    con_fvt = getNextFreeVT("console");
+                if (con_fvt >= 0 && con_fvt != getNextFreeVT(ut->ut_line))
+                    continue;
+#else
                 /* this check is probably linux-specific. */
-                /* alternatively we could open the device and try VT_OPENQRY. */
                 if (memcmp(ut->ut_line, "tty", 3) || !isdigit(ut->ut_line[3]))
                     continue;
+#endif
             }
             if (strNChrCnt(ut->ut_line, sizeof(ut->ut_line), ':'))
                 continue; /* x login */