Mercurial > vim
annotate src/pty.c @ 27737:9e05a238b0f0
Added tag v8.2.4394 for changeset ef89db30e46cab68e2bb6befc040e3960da9e94c
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 15 Feb 2022 21:00:04 +0100 |
parents | 41a61dbb46d2 |
children | 9781c150eddd |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 /* | |
10 * The stuff in this file mostly comes from the "screen" program. | |
11 * Included with permission from Juergen Weigert. | |
12 * Copied from "pty.c". "putenv.c" was used for putenv() in misc2.c. | |
13 * | |
14 * It has been modified to work better with Vim. | |
15 * The parts that are not used in Vim have been deleted. | |
16 * See the "screen" sources for the complete stuff. | |
3282 | 17 * |
18498
9e6d5a4abb1c
patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
18051
diff
changeset
|
18 * This specific version is distributed under the Vim license (attribution by |
3282 | 19 * Juergen Weigert), the GPL applies to the original version, see the |
20 * copyright notice below. | |
7 | 21 */ |
22 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
23 // Copyright (c) 1993 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
24 // Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
25 // Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
26 // Copyright (c) 1987 Oliver Laumann |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
27 // |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
28 // This program is free software; you can redistribute it and/or modify |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
29 // it under the terms of the GNU General Public License as published by |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
30 // the Free Software Foundation; either version 2, or (at your option) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
31 // any later version. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
32 // |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
33 // This program is distributed in the hope that it will be useful, |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
34 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
35 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
36 // GNU General Public License for more details. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
37 // |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
38 // You should have received a copy of the GNU General Public License |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
39 // along with this program (see the file COPYING); if not, write to the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
40 // Free Software Foundation, Inc., |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
41 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
7 | 42 |
43 #include "vim.h" | |
44 | |
11737
7791a15353dc
patch 8.0.0751: OpenPTY missing with some combination of features
Christian Brabandt <cb@256bit.org>
parents:
11735
diff
changeset
|
45 #if defined(FEAT_GUI) || defined(FEAT_JOB_CHANNEL) |
11735
21354977aa7b
patch 8.0.0750: OpenPTY missing in non-GUI build
Christian Brabandt <cb@256bit.org>
parents:
10460
diff
changeset
|
46 |
7 | 47 #include <signal.h> |
48 | |
1030 | 49 #ifdef HAVE_SYS_IOCTL_H |
7 | 50 # include <sys/ioctl.h> |
51 #endif | |
52 | |
53 #if HAVE_STROPTS_H | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
54 # include <sys/types.h> |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
55 # ifdef sinix |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
56 # define buf_T __system_buf_t__ |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
57 # endif |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
58 # include <stropts.h> |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
59 # ifdef sinix |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
60 # undef buf_T |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
61 # endif |
10460
7fd589f46801
commit https://github.com/vim/vim/commit/a899e6ecc4523c7e411eaf6fbaa4197d70f6f39e
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
62 # ifdef SUN_SYSTEM |
7 | 63 # include <sys/conf.h> |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
64 # if defined(HAVE_SYS_PTMS_H) && defined(HAVE_SVR4_PTYS) |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
65 # include <sys/ptms.h> |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
66 # endif |
7 | 67 # endif |
68 #endif | |
69 | |
1030 | 70 #ifdef HAVE_UNISTD_H |
7 | 71 # include <unistd.h> |
72 #endif | |
73 | |
74 #if HAVE_TERMIO_H | |
75 # include <termio.h> | |
76 #else | |
1030 | 77 # ifdef HAVE_TERMIOS_H |
7 | 78 # include <termios.h> |
79 # endif | |
80 #endif | |
81 | |
82 #if HAVE_SYS_STREAM_H | |
83 # include <sys/stream.h> | |
84 #endif | |
85 | |
86 #if HAVE_SYS_PTEM_H | |
87 # include <sys/ptem.h> | |
88 #endif | |
89 | |
12716
351cf7c67bbe
patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents:
12576
diff
changeset
|
90 #if !defined(SUN_SYSTEM) && !defined(VMS) |
7 | 91 # include <sys/ioctl.h> |
92 #endif | |
93 | |
10460
7fd589f46801
commit https://github.com/vim/vim/commit/a899e6ecc4523c7e411eaf6fbaa4197d70f6f39e
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
94 #if defined(SUN_SYSTEM) && defined(LOCKPTY) && !defined(TIOCEXCL) |
7 | 95 # include <sys/ttold.h> |
96 #endif | |
97 | |
98 #ifdef ISC | |
99 # include <sys/tty.h> | |
100 # include <sys/sioctl.h> | |
101 # include <sys/pty.h> | |
102 #endif | |
103 | |
104 #ifdef sgi | |
105 # include <sys/sysmacros.h> | |
106 #endif | |
107 | |
108 #if defined(_INCLUDE_HPUX_SOURCE) && !defined(hpux) | |
109 # define hpux | |
110 #endif | |
111 | |
112 /* | |
113 * if no PTYRANGE[01] is in the config file, we pick a default | |
114 */ | |
115 #ifndef PTYRANGE0 | |
116 # define PTYRANGE0 "qprs" | |
117 #endif | |
118 #ifndef PTYRANGE1 | |
119 # define PTYRANGE1 "0123456789abcdef" | |
120 #endif | |
121 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
122 // SVR4 pseudo ttys don't seem to work with SCO-5 |
7 | 123 #ifdef M_UNIX |
124 # undef HAVE_SVR4_PTYS | |
125 #endif | |
126 | |
127 /* | |
2834 | 128 * Open all ptys with O_NOCTTY, just to be on the safe side. |
7 | 129 */ |
130 #ifndef O_NOCTTY | |
131 # define O_NOCTTY 0 | |
132 #endif | |
133 | |
16441
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
134 #if defined(HAVE_SVR4_PTYS) || defined(HAVE_POSIX_OPENPT) |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
135 // These should be in stdlib.h, but it depends on _XOPEN_SOURCE. |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
136 char *ptsname(int); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
137 int unlockpt(int); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
138 int grantpt(int); |
16449
fd57da82dd5d
patch 8.1.1229: warning for posix_openpt() not declared
Bram Moolenaar <Bram@vim.org>
parents:
16441
diff
changeset
|
139 int posix_openpt(int flags); |
16441
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
140 #endif |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
141 |
7 | 142 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7807
diff
changeset
|
143 initmaster(int f UNUSED) |
7 | 144 { |
145 #ifndef VMS | |
146 # ifdef POSIX | |
147 tcflush(f, TCIOFLUSH); | |
148 # else | |
149 # ifdef TIOCFLUSH | |
150 (void)ioctl(f, TIOCFLUSH, (char *) 0); | |
151 # endif | |
152 # endif | |
153 # ifdef LOCKPTY | |
154 (void)ioctl(f, TIOCEXCL, (char *) 0); | |
155 # endif | |
156 #endif | |
157 } | |
158 | |
159 /* | |
160 * This causes a hang on some systems, but is required for a properly working | |
161 * pty on others. Needs to be tuned... | |
162 */ | |
163 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
164 setup_slavepty(int fd) |
7 | 165 { |
166 if (fd < 0) | |
167 return 0; | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
168 #if defined(I_PUSH) && defined(HAVE_SVR4_PTYS) && !defined(sgi) \ |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
169 && !defined(linux) && !defined(__osf__) && !defined(M_UNIX) |
7 | 170 # if defined(HAVE_SYS_PTEM_H) || defined(hpux) |
171 if (ioctl(fd, I_PUSH, "ptem") != 0) | |
172 return -1; | |
173 # endif | |
174 if (ioctl(fd, I_PUSH, "ldterm") != 0) | |
175 return -1; | |
10460
7fd589f46801
commit https://github.com/vim/vim/commit/a899e6ecc4523c7e411eaf6fbaa4197d70f6f39e
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
176 # ifdef SUN_SYSTEM |
7 | 177 if (ioctl(fd, I_PUSH, "ttcompat") != 0) |
178 return -1; | |
179 # endif | |
180 #endif | |
181 return 0; | |
182 } | |
183 | |
16441
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
184 #if defined(HAVE_POSIX_OPENPT) && !defined(PTY_DONE) |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
185 #define PTY_DONE |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
186 int |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
187 mch_openpty(char **ttyn) |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
188 { |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
189 int f; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
190 char *m; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
191 RETSIGTYPE (*sigcld) SIGPROTOARG; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
192 static char TtyName[32]; // used for opening a new pty-pair |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
193 |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
194 if ((f = posix_openpt(O_RDWR | O_NOCTTY | O_EXTRA)) == -1) |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
195 return -1; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
196 |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
197 // SIGCHLD set to SIG_DFL for grantpt() because it fork()s and |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
198 // exec()s pt_chmod |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
199 sigcld = signal(SIGCHLD, SIG_DFL); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
200 if ((m = ptsname(f)) == NULL || grantpt(f) || unlockpt(f)) |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
201 { |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
202 signal(SIGCHLD, sigcld); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
203 close(f); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
204 return -1; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
205 } |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
206 signal(SIGCHLD, sigcld); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
207 vim_strncpy((char_u *)TtyName, (char_u *)m, sizeof(TtyName) - 1); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
208 initmaster(f); |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
209 *ttyn = TtyName; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
210 return f; |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
211 } |
c1dca26a6949
patch 8.1.1225: cannot create a pty to use with :terminal on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents:
15632
diff
changeset
|
212 #endif |
7 | 213 |
214 #if defined(OSX) && !defined(PTY_DONE) | |
215 #define PTY_DONE | |
216 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
217 mch_openpty(char **ttyn) |
7 | 218 { |
219 int f; | |
220 static char TtyName[32]; | |
221 | |
222 if ((f = open_controlling_pty(TtyName)) < 0) | |
223 return -1; | |
224 initmaster(f); | |
225 *ttyn = TtyName; | |
226 return f; | |
227 } | |
228 #endif | |
229 | |
230 #if (defined(sequent) || defined(_SEQUENT_)) && defined(HAVE_GETPSEUDOTTY) \ | |
231 && !defined(PTY_DONE) | |
232 #define PTY_DONE | |
233 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
234 mch_openpty(char **ttyn) |
7 | 235 { |
236 char *m, *s; | |
237 int f; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
238 // used for opening a new pty-pair: |
7 | 239 static char PtyName[32]; |
240 static char TtyName[32]; | |
241 | |
242 if ((f = getpseudotty(&s, &m)) < 0) | |
243 return -1; | |
244 #ifdef _SEQUENT_ | |
245 fvhangup(s); | |
246 #endif | |
2760 | 247 vim_strncpy((char_u *)PtyName, (char_u *)m, sizeof(PtyName) - 1); |
248 vim_strncpy((char_u *)TtyName, (char_u *)s, sizeof(TtyName) - 1); | |
7 | 249 initmaster(f); |
250 *ttyn = TtyName; | |
251 return f; | |
252 } | |
253 #endif | |
254 | |
255 #if defined(__sgi) && !defined(PTY_DONE) | |
256 #define PTY_DONE | |
257 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
258 mch_openpty(char **ttyn) |
7 | 259 { |
260 int f; | |
261 char *name; | |
7807
1a5d34492798
commit https://github.com/vim/vim/commit/d99df423c559d85c17779b3685426c489554908c
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
262 RETSIGTYPE (*sigcld) SIGPROTOARG; |
7 | 263 |
264 /* | |
265 * SIGCHLD set to SIG_DFL for _getpty() because it may fork() and | |
266 * exec() /usr/adm/mkpts | |
267 */ | |
268 sigcld = signal(SIGCHLD, SIG_DFL); | |
269 name = _getpty(&f, O_RDWR | O_NONBLOCK | O_EXTRA, 0600, 0); | |
270 signal(SIGCHLD, sigcld); | |
271 | |
272 if (name == 0) | |
273 return -1; | |
274 initmaster(f); | |
275 *ttyn = name; | |
276 return f; | |
277 } | |
278 #endif | |
279 | |
280 #if defined(MIPS) && defined(HAVE_DEV_PTC) && !defined(PTY_DONE) | |
281 #define PTY_DONE | |
282 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
283 mch_openpty(char **ttyn) |
7 | 284 { |
285 int f; | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
7856
diff
changeset
|
286 stat_T buf; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
287 // used for opening a new pty-pair: |
7 | 288 static char TtyName[32]; |
289 | |
290 if ((f = open("/dev/ptc", O_RDWR | O_NOCTTY | O_NONBLOCK | O_EXTRA, 0)) < 0) | |
291 return -1; | |
292 if (mch_fstat(f, &buf) < 0) | |
293 { | |
294 close(f); | |
295 return -1; | |
296 } | |
297 sprintf(TtyName, "/dev/ttyq%d", minor(buf.st_rdev)); | |
298 initmaster(f); | |
299 *ttyn = TtyName; | |
300 return f; | |
301 } | |
302 #endif | |
303 | |
12576
b74f5036a434
patch 8.0.1166: :terminal doesn't work on Mac High Sierra
Christian Brabandt <cb@256bit.org>
parents:
11737
diff
changeset
|
304 #if defined(HAVE_SVR4_PTYS) && !defined(PTY_DONE) && !defined(hpux) \ |
13353
8412df1479a3
patch 8.0.1550: various small problems in source files
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
305 && !(defined(MACOS_X) && !defined(MAC_OS_X_VERSION_10_6)) |
7 | 306 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
307 // NOTE: Even though HPUX can have /dev/ptmx, the code below doesn't work! |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
308 // Same for Mac OS X Leopard (10.5). |
7 | 309 #define PTY_DONE |
310 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
311 mch_openpty(char **ttyn) |
7 | 312 { |
313 int f; | |
2397
d5976fe4349d
Fix for compiler warning about function prototype in pty.c.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
314 char *m; |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
3282
diff
changeset
|
315 RETSIGTYPE (*sigcld) SIGPROTOARG; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
316 // used for opening a new pty-pair: |
7 | 317 static char TtyName[32]; |
318 | |
319 if ((f = open("/dev/ptmx", O_RDWR | O_NOCTTY | O_EXTRA, 0)) == -1) | |
320 return -1; | |
321 | |
322 /* | |
323 * SIGCHLD set to SIG_DFL for grantpt() because it fork()s and | |
324 * exec()s pt_chmod | |
325 */ | |
326 sigcld = signal(SIGCHLD, SIG_DFL); | |
327 if ((m = ptsname(f)) == NULL || grantpt(f) || unlockpt(f)) | |
328 { | |
329 signal(SIGCHLD, sigcld); | |
330 close(f); | |
331 return -1; | |
332 } | |
333 signal(SIGCHLD, sigcld); | |
2760 | 334 vim_strncpy((char_u *)TtyName, (char_u *)m, sizeof(TtyName) - 1); |
7 | 335 initmaster(f); |
336 *ttyn = TtyName; | |
337 return f; | |
338 } | |
339 #endif | |
340 | |
341 #if defined(_AIX) && defined(HAVE_DEV_PTC) && !defined(PTY_DONE) | |
342 #define PTY_DONE | |
343 | |
344 #ifdef _IBMR2 | |
18051
d1e77015f60b
patch 8.1.2021: some global functions can be local to the file
Bram Moolenaar <Bram@vim.org>
parents:
16449
diff
changeset
|
345 static int aixhack = -1; |
7 | 346 #endif |
347 | |
348 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
349 mch_openpty(char **ttyn) |
7 | 350 { |
351 int f; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
352 // used for opening a new pty-pair: |
7 | 353 static char TtyName[32]; |
354 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
355 // a dumb looking loop replaced by mycrofts code: |
7 | 356 if ((f = open("/dev/ptc", O_RDWR | O_NOCTTY | O_EXTRA)) < 0) |
357 return -1; | |
2760 | 358 vim_strncpy((char_u *)TtyName, (char_u *)ttyname(f), sizeof(TtyName) - 1); |
1076 | 359 if (geteuid() != ROOT_UID && mch_access(TtyName, R_OK | W_OK)) |
7 | 360 { |
361 close(f); | |
362 return -1; | |
363 } | |
364 initmaster(f); | |
365 # ifdef _IBMR2 | |
366 if (aixhack >= 0) | |
367 close(aixhack); | |
368 if ((aixhack = open(TtyName, O_RDWR | O_NOCTTY | O_EXTRA, 0)) < 0) | |
369 { | |
370 close(f); | |
371 return -1; | |
372 } | |
373 # endif | |
374 *ttyn = TtyName; | |
375 return f; | |
376 } | |
377 #endif | |
378 | |
379 #ifndef PTY_DONE | |
380 | |
381 # ifdef hpux | |
382 static char PtyProto[] = "/dev/ptym/ptyXY"; | |
383 static char TtyProto[] = "/dev/pty/ttyXY"; | |
384 # else | |
20591
4411c2b96af9
patch 8.2.0849: BeOS code is not maintained and probably unused
Bram Moolenaar <Bram@vim.org>
parents:
19526
diff
changeset
|
385 # ifdef(__HAIKU__) |
7 | 386 static char PtyProto[] = "/dev/pt/XY"; |
387 static char TtyProto[] = "/dev/tt/XY"; | |
388 # else | |
389 static char PtyProto[] = "/dev/ptyXY"; | |
390 static char TtyProto[] = "/dev/ttyXY"; | |
391 # endif | |
392 # endif | |
393 | |
394 int | |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
395 mch_openpty(char **ttyn) |
7 | 396 { |
397 char *p, *q, *l, *d; | |
398 int f; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
399 // used for opening a new pty-pair: |
7 | 400 static char PtyName[32]; |
401 static char TtyName[32]; | |
402 | |
403 strcpy(PtyName, PtyProto); | |
404 strcpy(TtyName, TtyProto); | |
405 for (p = PtyName; *p != 'X'; p++) | |
406 ; | |
407 for (q = TtyName; *q != 'X'; q++) | |
408 ; | |
409 for (l = PTYRANGE0; (*p = *l) != '\0'; l++) | |
410 { | |
411 for (d = PTYRANGE1; (p[1] = *d) != '\0'; d++) | |
412 { | |
413 if ((f = open(PtyName, O_RDWR | O_NOCTTY | O_EXTRA, 0)) == -1) | |
414 continue; | |
415 q[0] = *l; | |
416 q[1] = *d; | |
1076 | 417 if (geteuid() != ROOT_UID && mch_access(TtyName, R_OK | W_OK)) |
7 | 418 { |
419 close(f); | |
420 continue; | |
421 } | |
10460
7fd589f46801
commit https://github.com/vim/vim/commit/a899e6ecc4523c7e411eaf6fbaa4197d70f6f39e
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
422 #if defined(SUN_SYSTEM) && defined(TIOCGPGRP) && !defined(SUNOS3) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
423 // Hack to ensure that the slave side of the pty is |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
424 // unused. May not work in anything other than SunOS4.1 |
7 | 425 { |
426 int pgrp; | |
427 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
428 // tcgetpgrp does not work (uses TIOCGETPGRP)! |
7 | 429 if (ioctl(f, TIOCGPGRP, (char *)&pgrp) != -1 || errno != EIO) |
430 { | |
431 close(f); | |
432 continue; | |
433 } | |
434 } | |
435 #endif | |
436 initmaster(f); | |
437 *ttyn = TtyName; | |
438 return f; | |
439 } | |
440 } | |
441 return -1; | |
442 } | |
443 #endif | |
11735
21354977aa7b
patch 8.0.0750: OpenPTY missing in non-GUI build
Christian Brabandt <cb@256bit.org>
parents:
10460
diff
changeset
|
444 |
15632
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
445 /* |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
446 * Call isatty(fd), except for SunOS where it's done differently. |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
447 */ |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
448 int |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
449 mch_isatty(int fd) |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
450 { |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
451 # if defined(I_STR) && defined(HAVE_SYS_PTMS_H) && defined(HAVE_SVR4_PTYS) \ |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
452 && defined(SUN_SYSTEM) |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
453 // On SunOS, isatty() for /dev/ptmx returns false or sometimes can hang up |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
454 // in the inner ioctl(), and therefore first determine whether "fd" is a |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
455 // master device. |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
456 struct strioctl istr; |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
457 |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
458 istr.ic_cmd = ISPTM; |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
459 istr.ic_timout = 0; |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
460 istr.ic_dp = NULL; |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
461 istr.ic_len = 0; |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
462 |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
463 if (ioctl(fd, I_STR, &istr) == 0) |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
464 // Trick: return 2 in order to advice the caller that "fd" is a master |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
465 // device. cf. src/os_unix.c:get_tty_fd() |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
466 return 2; |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
467 # endif |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
468 return isatty(fd); |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
469 } |
d4a6d575e910
patch 8.1.0824: SunOS/Solaris has a problem with ttys
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
470 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
471 #endif // FEAT_GUI || FEAT_JOB_CHANNEL |