Removed
Link Here
|
1 |
--- src/session/tty.c.orig 2016-08-19 13:28:50 UTC |
2 |
+++ src/session/tty.c |
3 |
@@ -9,27 +9,18 @@ |
4 |
#include "internal.h" |
5 |
#include "tty.h" |
6 |
|
7 |
-#if defined(__linux__) |
8 |
-# define TTY_BASENAME "/dev/tty" |
9 |
-# define TTY_0 "/dev/tty0" |
10 |
-# include <linux/kd.h> |
11 |
-# include <linux/major.h> |
12 |
-# include <linux/vt.h> |
13 |
-#elif defined(__FreeBSD__) |
14 |
+#if defined(__FreeBSD__) |
15 |
+# include <termios.h> |
16 |
# include <sys/consio.h> |
17 |
# include <sys/kbio.h> |
18 |
# define TTY_BASENAME "/dev/ttyv" |
19 |
# define TTY_0 "/dev/ttyv0" |
20 |
-# define TTY_MAJOR 0 |
21 |
-# define VT_GETSTATE 0x5603 |
22 |
-# define VT_ACTIVATE 0x5606 |
23 |
-# define K_UNICODE 0x03 |
24 |
-# define K_OFF 0x04 |
25 |
-struct vt_stat { |
26 |
- unsigned short v_active; /* active vt */ |
27 |
- unsigned short v_signal; /* signal to send */ |
28 |
- unsigned short v_state; /* vt bitmask */ |
29 |
-}; |
30 |
+#else |
31 |
+# include <linux/kd.h> |
32 |
+# include <linux/major.h> |
33 |
+# include <linux/vt.h> |
34 |
+# define TTY_BASENAME "/dev/tty" |
35 |
+# define TTY_0 "/dev/tty0" |
36 |
#endif |
37 |
|
38 |
#ifndef KDSKBMUTE |
39 |
@@ -100,22 +91,22 @@ open_tty(int vt) |
40 |
} |
41 |
|
42 |
static bool |
43 |
-setup_tty(int fd, bool replace_vt) |
44 |
+setup_tty(int fd, int vt, bool replace_vt) |
45 |
{ |
46 |
if (fd < 0) |
47 |
return false; |
48 |
|
49 |
+#if defined(__FreeBSD__) |
50 |
+ wlc.vt = vt+1; |
51 |
+#else |
52 |
struct stat st; |
53 |
if (fstat(fd, &st) == -1) |
54 |
die("Could not stat tty fd"); |
55 |
- |
56 |
wlc.vt = minor(st.st_rdev); |
57 |
- |
58 |
if (major(st.st_rdev) != TTY_MAJOR || wlc.vt == 0) |
59 |
die("Not a valid vt"); |
60 |
+#endif |
61 |
|
62 |
-/* FreeBSD's new vt is still missing some bits */ |
63 |
-#if defined(__linux__) |
64 |
if (!replace_vt) { |
65 |
int kd_mode; |
66 |
if (ioctl(fd, KDGETMODE, &kd_mode) == -1) |
67 |
@@ -125,18 +116,20 @@ setup_tty(int fd, bool replace_vt) |
68 |
die("vt%d is already in graphics mode (%d). Is another display server running?", wlc.vt, kd_mode); |
69 |
} |
70 |
|
71 |
+#if defined(__FreeBSD__) |
72 |
+ ioctl(fd, VT_GETACTIVE, &wlc.old_state.vt); |
73 |
+#else |
74 |
struct vt_stat state; |
75 |
if (ioctl(fd, VT_GETSTATE, &state) == -1) |
76 |
die("Could not get current vt"); |
77 |
- |
78 |
wlc.old_state.vt = state.v_active; |
79 |
+#endif |
80 |
|
81 |
if (ioctl(fd, VT_ACTIVATE, wlc.vt) == -1) |
82 |
die("Could not activate vt%d", wlc.vt); |
83 |
|
84 |
if (ioctl(fd, VT_WAITACTIVE, wlc.vt) == -1) |
85 |
die("Could not wait for vt%d to become active", wlc.vt); |
86 |
-#endif |
87 |
|
88 |
if (ioctl(fd, KDGKBMODE, &wlc.old_state.kb_mode) == -1) |
89 |
die("Could not get keyboard mode"); |
90 |
@@ -144,7 +137,19 @@ setup_tty(int fd, bool replace_vt) |
91 |
// vt will be restored from now on |
92 |
wlc.tty = fd; |
93 |
|
94 |
-#if defined(__linux__) |
95 |
+#if defined(__FreeBSD__) |
96 |
+ if (ioctl(fd, KDSKBMODE, K_CODE) == -1) { |
97 |
+ wlc_tty_terminate(); |
98 |
+ die("Could not set keyboard mode to K_CODE"); |
99 |
+ } |
100 |
+ /* Put the tty into raw mode */ |
101 |
+ struct termios tios; |
102 |
+ if (tcgetattr(fd, &tios)) |
103 |
+ die("Failed to get terminal attribute"); |
104 |
+ cfmakeraw(&tios); |
105 |
+ if (tcsetattr(fd, TCSANOW, &tios)) |
106 |
+ die("Failed to set terminal attribute"); |
107 |
+#else |
108 |
if (ioctl(fd, KDSKBMUTE, 1) == -1 && ioctl(fd, KDSKBMODE, K_OFF) == -1) { |
109 |
wlc_tty_terminate(); |
110 |
die("Could not set keyboard mode to K_OFF"); |
111 |
@@ -156,18 +161,19 @@ setup_tty(int fd, bool replace_vt) |
112 |
die("Could not set console mode to KD_GRAPHICS"); |
113 |
} |
114 |
|
115 |
-#if defined(__linux__) |
116 |
struct vt_mode mode = { |
117 |
.mode = VT_PROCESS, |
118 |
.relsig = SIGUSR1, |
119 |
.acqsig = SIGUSR2 |
120 |
}; |
121 |
+#if defined(__FreeBSD__) |
122 |
+ mode.frsig = SIGIO; /* not used, but has to be set anyway */ |
123 |
+#endif |
124 |
|
125 |
if (ioctl(fd, VT_SETMODE, &mode) == -1) { |
126 |
wlc_tty_terminate(); |
127 |
die("Could not set vt%d mode", wlc.vt); |
128 |
} |
129 |
-#endif |
130 |
|
131 |
return true; |
132 |
} |
133 |
@@ -230,13 +236,19 @@ wlc_tty_terminate(void) |
134 |
// The ACTIVATE / WAITACTIVE may be potentially bad here. |
135 |
// However, we need to make sure the vt we initially opened is also active on cleanup. |
136 |
// We can't make sure this is synchronized due to unclean exits. |
137 |
+ |
138 |
if (ioctl(wlc.tty, VT_ACTIVATE, wlc.vt) != -1 && ioctl(wlc.tty, VT_WAITACTIVE, wlc.vt) != -1) { |
139 |
wlc_log(WLC_LOG_INFO, "Restoring vt %d (0x%lx) (fd %d)", wlc.vt, wlc.old_state.kb_mode, wlc.tty); |
140 |
|
141 |
- if (ioctl(wlc.tty, KDSKBMUTE, 0) == -1 && |
142 |
- ioctl(wlc.tty, KDSKBMODE, wlc.old_state.kb_mode) == -1 && |
143 |
- ioctl(wlc.tty, KDSKBMODE, K_UNICODE) == -1) |
144 |
- wlc_log(WLC_LOG_ERROR, "Failed to restore vt%d KDSKMODE", wlc.vt); |
145 |
+#if defined(__FreeBSD__) |
146 |
+ if (ioctl(wlc.tty, KDSKBMODE, wlc.old_state.kb_mode) == -1 && |
147 |
+ ioctl(wlc.tty, KDSKBMODE, K_XLATE) == -1) |
148 |
+#else |
149 |
+ if (ioctl(wlc.tty, KDSKBMUTE, 0) == -1 && |
150 |
+ ioctl(wlc.tty, KDSKBMODE, wlc.old_state.kb_mode) == -1 && |
151 |
+ ioctl(wlc.tty, KDSKBMODE, K_UNICODE) == -1) |
152 |
+#endif |
153 |
+ wlc_log(WLC_LOG_ERROR, "Failed to restore vt%d KDSKMODE", wlc.vt); |
154 |
|
155 |
if (ioctl(wlc.tty, KDSETMODE, KD_TEXT) == -1) |
156 |
wlc_log(WLC_LOG_ERROR, "Failed to restore vt%d mode to VT_AUTO", wlc.vt); |
157 |
@@ -271,7 +283,7 @@ wlc_tty_init(int vt) |
158 |
if (!vt && !(vt = find_vt(getenv("XDG_VTNR"), &replace_vt))) |
159 |
die("Could not find vt"); |
160 |
|
161 |
- if (!setup_tty(open_tty(vt), replace_vt)) |
162 |
+ if (!setup_tty(open_tty(vt), vt, replace_vt)) |
163 |
die("Could not open tty with vt%d", vt); |
164 |
|
165 |
struct sigaction action = { |