forked from gentoo/gentoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
canfep-posix-pty.patch
67 lines (64 loc) · 1.63 KB
/
canfep-posix-pty.patch
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
https://bugs.gentoo.org/show_bug.cgi?id=212709
Author: OKUMURA N. Shin-ya <[email protected]>
--- a/pty.C
+++ b/pty.C
@@ -257,6 +257,23 @@
}
}
+#if defined(_POSIX_C_SOURCE)
+ // BSD pty が開けないので、POSIX の方法を試す
+ if ((master = posix_openpt(O_RDWR)) >= 0) {
+ if (grantpt(master) == 0 && unlockpt(master) == 0) {
+ // マスタデバイス名は固定
+ strcpy(line, "/dev/ptmx");
+ tcgetattr(0, &tt);
+ tt.c_iflag &= ~ISTRIP;
+ ioctl(0, TIOCGWINSZ, (char*) &win);
+ return;
+ }
+ close(master);
+ } else {
+ perror("/dev/ptmx");
+ }
+#endif // _POSIX_C_SOURCE
+
printf("Out of pty's\n");
fail();
}
@@ -265,12 +282,36 @@
void
Pty::getslave()
{
+#if defined(_POSIX_C_SOURCE)
+ // マスタデバイスが POSIX 方式の場合
+ if (strcmp(line, "/dev/ptmx") == 0) {
+ char *slave_devname = ptsname(master);
+ if (slave_devname == NULL) {
+ perror("ptsname");
+ fail();
+ }
+ slave = open(slave_devname, O_RDWR);
+ if (slave < 0) {
+ perror(slave_devname);
+ fail();
+ }
+ strcpy(line, slave_devname);
+ } else {
+ line[strlen("/dev/")] = 't';
+ slave = open(line, O_RDWR);
+ if (slave < 0) {
+ perror(line);
+ fail();
+ }
+ }
+#else // ! _POSIX_C_SOURCE
line[strlen("/dev/")] = 't';
slave = open(line, O_RDWR);
if (slave < 0) {
perror(line);
fail();
}
+#endif // _POSIX_C_SOURCE
tcsetattr(slave, TCSAFLUSH, &tt);
if (!hs)
win.ws_row--;