| @@ -1,66 +1,68 @@ | | | @@ -1,66 +1,68 @@ |
1 | $NetBSD: patch-aj,v 1.9 2006/01/17 21:23:01 kristerw Exp $ | | 1 | $NetBSD: patch-aj,v 1.10 2011/09/29 20:22:26 wiz Exp $ |
2 | | | 2 | |
3 | --- fep_main.c.orig 1993-06-10 02:53:06.000000000 +0000 | | 3 | --- fep_main.c.orig 1993-06-10 02:53:06.000000000 +0000 |
4 | +++ fep_main.c 2006-01-03 18:13:49.000000000 +0000 | | 4 | +++ fep_main.c 2011-09-29 20:16:05.000000000 +0000 |
5 | @@ -6 +6 @@ | | 5 | @@ -6,15 +6,24 @@ |
6 | -#endif lint | | 6 | -#endif lint |
7 | +#endif /* lint */ | | 7 | +#endif /* lint */ |
8 | @@ -10,11 +10,20 @@ | | 8 | |
| | | 9 | #include <stdio.h> |
| | | 10 | #include <signal.h> |
9 | #include <sys/types.h> | | 11 | #include <sys/types.h> |
10 | #include <sys/stat.h> | | 12 | #include <sys/stat.h> |
11 | #include <sys/ioctl.h> | | 13 | #include <sys/ioctl.h> |
12 | -#include <sys/file.h> | | 14 | -#include <sys/file.h> |
13 | +#ifdef TERMIOS | | 15 | +#ifdef TERMIOS |
14 | +#include <stdlib.h> | | 16 | +#include <stdlib.h> |
15 | +#include <fcntl.h> | | 17 | +#include <fcntl.h> |
16 | +#include <termios.h> | | 18 | +#include <termios.h> |
17 | +#ifndef _POSIX_VDISABLE | | 19 | +#ifndef _POSIX_VDISABLE |
18 | +#define _POSIX_VDISABLE '\0' | | 20 | +#define _POSIX_VDISABLE '\0' |
19 | +#endif | | 21 | +#endif |
20 | +#else | | 22 | +#else |
21 | #include <sgtty.h> | | 23 | #include <sgtty.h> |
22 | +#include <sys/file.h> | | 24 | +#include <sys/file.h> |
23 | +#endif | | 25 | +#endif |
24 | #include <sys/time.h> | | 26 | #include <sys/time.h> |
25 | #include <sys/resource.h> | | 27 | #include <sys/resource.h> |
26 | -#include <sys/errno.h> | | 28 | -#include <sys/errno.h> |
27 | +#include <errno.h> | | 29 | +#include <errno.h> |
28 | | | 30 | |
29 | #include "fep_defs.h" | | 31 | #include "fep_defs.h" |
30 | #include "fep_glob.h" | | 32 | #include "fep_glob.h" |
31 | @@ -30,7 +39,7 @@ static char rcsid[]= | | 33 | @@ -30,7 +39,7 @@ |
32 | #ifdef STAT | | 34 | #ifdef STAT |
33 | static char fep_statrc[] = FEP_STAT; | | 35 | static char fep_statrc[] = FEP_STAT; |
34 | #endif | | 36 | #endif |
35 | -#endif lint | | 37 | -#endif lint |
36 | +#endif /* lint */ | | 38 | +#endif /* lint */ |
37 | | | 39 | |
38 | char *myself; /* the command name */ | | 40 | char *myself; /* the command name */ |
39 | char *prompt = ""; /* prompt string */ | | 41 | char *prompt = ""; /* prompt string */ |
40 | @@ -38,9 +47,9 @@ char *delimiters = DEFAULT_DELIMITERS; | | 42 | @@ -38,9 +47,9 @@ |
41 | /* delimiter characters */ | | 43 | /* delimiter characters */ |
42 | int master; /* file discriptor for pty master */ | | 44 | int master; /* file discriptor for pty master */ |
43 | int slave; /* file discriptor for pty slave */ | | 45 | int slave; /* file discriptor for pty slave */ |
44 | -int mastermask; /* 1<<master */ | | 46 | -int mastermask; /* 1<<master */ |
45 | -int stdinmask; /* 1<<fileno(stdin) */ | | 47 | -int stdinmask; /* 1<<fileno(stdin) */ |
46 | -int selectmask; /* stdinmask | mastermask */ | | 48 | -int selectmask; /* stdinmask | mastermask */ |
47 | +fd_set mastermask; /* 1<<master */ | | 49 | +fd_set mastermask; /* 1<<master */ |
48 | +fd_set stdinmask; /* 1<<fileno(stdin) */ | | 50 | +fd_set stdinmask; /* 1<<fileno(stdin) */ |
49 | +fd_set selectmask; /* stdinmask | mastermask */ | | 51 | +fd_set selectmask; /* stdinmask | mastermask */ |
50 | int selectnfds; /* max (fileno(stdin), master) + 1*/ | | 52 | int selectnfds; /* max (fileno(stdin), master) + 1*/ |
51 | int child_pid; /* child pid */ | | 53 | int child_pid; /* child pid */ |
52 | int ptyflag = ON; /* flag to use pty or not */ | | 54 | int ptyflag = ON; /* flag to use pty or not */ |
53 | @@ -48,27 +57,34 @@ int histlen = -1; /* history length */ | | 55 | @@ -48,27 +57,34 @@ |
54 | int debug = OFF; /* debug switch */ | | 56 | int debug = OFF; /* debug switch */ |
55 | int auto_tty_fix = ON; /* fix tty mode automaticaly */ | | 57 | int auto_tty_fix = ON; /* fix tty mode automaticaly */ |
56 | FILE *script_fp = NULL; /* script file pointer */ | | 58 | FILE *script_fp = NULL; /* script file pointer */ |
57 | -int catchsig(); /* function take care SIGCHILD */ | | 59 | -int catchsig(); /* function take care SIGCHILD */ |
58 | +void catchsig __P((int)); /* function take care SIGCHILD */ | | 60 | +void catchsig __P((int)); /* function take care SIGCHILD */ |
59 | | | 61 | |
60 | -struct sgttyb initial_ttymode; /* initial tty mode */ | | 62 | -struct sgttyb initial_ttymode; /* initial tty mode */ |
61 | -struct sgttyb master_ttymode; /* master tty mode */ | | 63 | -struct sgttyb master_ttymode; /* master tty mode */ |
62 | -struct sgttyb slave_ttymode; /* slave tty mode */ | | 64 | -struct sgttyb slave_ttymode; /* slave tty mode */ |
63 | +#ifdef TERMIOS | | 65 | +#ifdef TERMIOS |
64 | +#define ttystruct termios | | 66 | +#define ttystruct termios |
65 | +#elif defined(TIOCSETN) | | 67 | +#elif defined(TIOCSETN) |
66 | +#define ttystruct sgttyb | | 68 | +#define ttystruct sgttyb |
| @@ -81,154 +83,181 @@ $NetBSD: patch-aj,v 1.9 2006/01/17 21:23 | | | @@ -81,154 +83,181 @@ $NetBSD: patch-aj,v 1.9 2006/01/17 21:23 |
81 | struct tchars tchars_buf; /* tty characters */ | | 83 | struct tchars tchars_buf; /* tty characters */ |
82 | struct ltchars ltchars_buf; /* tty characters */ | | 84 | struct ltchars ltchars_buf; /* tty characters */ |
83 | +#endif | | 85 | +#endif |
84 | int lmode_buf; /* local mode */ | | 86 | int lmode_buf; /* local mode */ |
85 | int line_desc; /* line descipline */ | | 87 | int line_desc; /* line descipline */ |
86 | #ifdef KANJI | | 88 | #ifdef KANJI |
87 | struct jtchars jtchars_buf; /* kanji tty characters */ | | 89 | struct jtchars jtchars_buf; /* kanji tty characters */ |
88 | int kmode_buf; /* kanji mode */ | | 90 | int kmode_buf; /* kanji mode */ |
89 | -#endif KANJI | | 91 | -#endif KANJI |
90 | +#endif /* KANJI */ | | 92 | +#endif /* KANJI */ |
91 | | | 93 | |
92 | char master_tty[16]; /* master tty name */ | | 94 | char master_tty[16]; /* master tty name */ |
93 | char slave_tty[16]; /* slave tty name */ | | 95 | char slave_tty[16]; /* slave tty name */ |
94 | @@ -112,6 +128,10 @@ main(argc, argv) | | 96 | @@ -112,6 +128,10 @@ |
95 | | | 97 | |
96 | myself = argv[0]; | | 98 | myself = argv[0]; |
97 | | | 99 | |
98 | + setvbuf(stdin, NULL, _IONBF, 0); | | 100 | + setvbuf(stdin, NULL, _IONBF, 0); |
99 | + setvbuf(stdout, NULL, _IONBF, 0); | | 101 | + setvbuf(stdout, NULL, _IONBF, 0); |
100 | + setvbuf(stderr, NULL, _IONBF, 0); | | 102 | + setvbuf(stderr, NULL, _IONBF, 0); |
101 | + | | 103 | + |
102 | /* | | 104 | /* |
103 | * Initialize binding table | | 105 | * Initialize binding table |
104 | */ | | 106 | */ |
105 | @@ -172,7 +192,7 @@ main(argc, argv) | | 107 | @@ -172,7 +192,7 @@ |
106 | histlen = atoi (argv[1]); | | 108 | histlen = atoi (argv[1]); |
107 | } | | 109 | } |
108 | else { | | 110 | else { |
109 | - histlen = atoi (&argv[1] + 2); | | 111 | - histlen = atoi (&argv[1] + 2); |
110 | + histlen = atoi (argv[1] + 2); | | 112 | + histlen = atoi (argv[1] + 2); |
111 | } | | 113 | } |
112 | break; | | 114 | break; |
113 | | | 115 | |
114 | @@ -276,7 +296,7 @@ DEFAULT: | | 116 | @@ -276,7 +296,7 @@ |
115 | fix_signal () | | 117 | fix_signal () |
116 | { | | 118 | { |
117 | #ifdef SIGWINCH | | 119 | #ifdef SIGWINCH |
118 | - int sigwinch(); | | 120 | - int sigwinch(); |
119 | + void sigwinch __P((int)); | | 121 | + void sigwinch __P((int)); |
120 | #endif | | 122 | #endif |
121 | | | 123 | |
122 | sighup = signal (SIGHUP, terminate); | | 124 | sighup = signal (SIGHUP, terminate); |
123 | @@ -336,7 +356,7 @@ input_handler() | | 125 | @@ -298,7 +318,7 @@ |
| | | 126 | input_handler() |
| | | 127 | { |
| | | 128 | char *inputline; |
| | | 129 | - char *getline (); |
| | | 130 | + char *get_line (); |
| | | 131 | |
| | | 132 | /* |
| | | 133 | * Get slave tty descriptor for auto-tty-fix |
| | | 134 | @@ -306,7 +326,7 @@ |
| | | 135 | if ((slave = open (slave_tty, O_RDONLY)) < 0) |
| | | 136 | perror ("open"); |
| | | 137 | |
| | | 138 | - while (inputline = getline ()) { |
| | | 139 | + while (inputline = get_line ()) { |
| | | 140 | /* |
| | | 141 | * XXX: nbyte should be greater than 0 only for ^@ input in emacs. |
| | | 142 | * This solution is very ugly.. but it will takes a half day |
| | | 143 | @@ -322,7 +342,7 @@ |
| | | 144 | |
| | | 145 | /* |
| | | 146 | * NOTE: |
| | | 147 | - * Saving command line to output buffer is done in getline(). |
| | | 148 | + * Saving command line to output buffer is done in get_line(). |
| | | 149 | * Because inputline here is converted by alias. |
| | | 150 | */ |
| | | 151 | |
| | | 152 | @@ -336,7 +356,7 @@ |
124 | if (Through == OFF && Transparency == OFF && script_fp) | | 153 | if (Through == OFF && Transparency == OFF && script_fp) |
125 | fwrite (inputline, sizeof(CHAR), strlen (inputline), script_fp); | | 154 | fwrite (inputline, sizeof(CHAR), strlen (inputline), script_fp); |
126 | } | | 155 | } |
127 | - terminate (); | | 156 | - terminate (); |
128 | + terminate (0); | | 157 | + terminate (0); |
129 | } | | 158 | } |
130 | | | 159 | |
131 | #define INPUT_BUFFER_SIZE 1024 | | 160 | #define INPUT_BUFFER_SIZE 1024 |
132 | @@ -384,21 +404,19 @@ getcharacter() | | 161 | @@ -384,21 +404,19 @@ |
133 | { | | 162 | { |
134 | char c; | | 163 | char c; |
135 | int n; | | 164 | int n; |
136 | - int nfound, readfd, writefd = 0, execptfd = 0; | | 165 | - int nfound, readfd, writefd = 0, execptfd = 0; |
137 | + int nfound; | | 166 | + int nfound; |
138 | + fd_set readfd, writefd, exceptfd; | | 167 | + fd_set readfd, writefd, exceptfd; |
139 | #ifdef USE_TIMEOUT | | 168 | #ifdef USE_TIMEOUT |
140 | struct timeval **timeout = auto_tty_fix ? timeout_list : notimeout; | | 169 | struct timeval **timeout = auto_tty_fix ? timeout_list : notimeout; |
141 | #else | | 170 | #else |
142 | struct timeval **timeout = notimeout; | | 171 | struct timeval **timeout = notimeout; |
143 | #endif | | 172 | #endif |
144 | - extern int errno; | | 173 | - extern int errno; |
145 | - | | 174 | - |
146 | | | 175 | |
147 | /* | | 176 | /* |
148 | * Sorry, this cording depends to an implementation of getc(). | | 177 | * Sorry, this cording depends to an implementation of getc(). |
149 | */ | | 178 | */ |
150 | -# define CHAR_IN_BUFFER (stdin->_cnt) | | 179 | -# define CHAR_IN_BUFFER (stdin->_cnt) |
151 | - if (CHAR_IN_BUFFER) | | 180 | - if (CHAR_IN_BUFFER) |
152 | - goto RETURNCHAR; | | 181 | - goto RETURNCHAR; |
153 | + FD_ZERO(&writefd); | | 182 | + FD_ZERO(&writefd); |
154 | + FD_ZERO(&exceptfd); | | 183 | + FD_ZERO(&exceptfd); |
155 | | | 184 | |
156 | RETRY: | | 185 | RETRY: |
157 | readfd = selectmask; | | 186 | readfd = selectmask; |
158 | @@ -409,13 +427,13 @@ RETRY: | | 187 | @@ -409,13 +427,13 @@ |
159 | while ((nfound = select (selectnfds, &readfd, 0, 0, *timeout)) < 0) | | 188 | while ((nfound = select (selectnfds, &readfd, 0, 0, *timeout)) < 0) |
160 | if (errno != EINTR) { | | 189 | if (errno != EINTR) { |
161 | perror ("select"); | | 190 | perror ("select"); |
162 | - terminate(); | | 191 | - terminate(); |
163 | + terminate(1); | | 192 | + terminate(1); |
164 | } | | 193 | } |
165 | | | 194 | |
166 | /* | | 195 | /* |
167 | * Found output from pty. | | 196 | * Found output from pty. |
168 | */ | | 197 | */ |
169 | - if (readfd & mastermask) { | | 198 | - if (readfd & mastermask) { |
170 | + if (FD_ISSET(master, &readfd)) { | | 199 | + if (FD_ISSET(master, &readfd)) { |
171 | int nbyte; | | 200 | int nbyte; |
172 | | | 201 | |
173 | /* | | 202 | /* |
174 | @@ -451,7 +469,7 @@ RETRY: | | 203 | @@ -451,7 +469,7 @@ |
175 | /* | | 204 | /* |
176 | * Found input from terminal | | 205 | * Found input from terminal |
177 | */ | | 206 | */ |
178 | - if (CHAR_IN_BUFFER || readfd & stdinmask) { | | 207 | - if (CHAR_IN_BUFFER || readfd & stdinmask) { |
179 | + if (FD_ISSET(fileno(stdin), &readfd)) { | | 208 | + if (FD_ISSET(fileno(stdin), &readfd)) { |
180 | | | 209 | |
181 | #ifndef USE_TIMEOUT | | 210 | #ifndef USE_TIMEOUT |
182 | /* | | 211 | /* |
183 | @@ -467,8 +485,8 @@ RETRY: | | 212 | @@ -467,8 +485,8 @@ |
184 | RETURNCHAR: | | 213 | RETURNCHAR: |
185 | if ((c = getc (stdin)) == EOF) { | | 214 | if ((c = getc (stdin)) == EOF) { |
186 | if (debug) | | 215 | if (debug) |
187 | - printf ("EOF chatched\n"); | | 216 | - printf ("EOF chatched\n"); |
188 | - terminate (); | | 217 | - terminate (); |
189 | + printf ("EOF catched\n"); | | 218 | + printf ("EOF catched\n"); |
190 | + terminate (1); | | 219 | + terminate (1); |
191 | } | | 220 | } |
192 | else | | 221 | else |
193 | return (c & CHARMASK); | | 222 | return (c & CHARMASK); |
194 | @@ -504,7 +522,7 @@ int set_buffer (bp, size) | | 223 | @@ -504,7 +522,7 @@ |
195 | BUFFER *bp; | | 224 | BUFFER *bp; |
196 | int size; | | 225 | int size; |
197 | { | | 226 | { |
198 | - char *newbuf, *malloc(), *realloc(); | | 227 | - char *newbuf, *malloc(), *realloc(); |
199 | + char *newbuf; | | 228 | + char *newbuf; |
200 | | | 229 | |
201 | if (bp->b_buf) | | 230 | if (bp->b_buf) |
202 | newbuf = (char *) realloc (bp->b_buf, size); | | 231 | newbuf = (char *) realloc (bp->b_buf, size); |
203 | @@ -596,7 +614,7 @@ buf_put (bp, s) | | 232 | @@ -596,7 +614,7 @@ |
204 | | | 233 | |
205 | swallow_output() | | 234 | swallow_output() |
206 | { | | 235 | { |
207 | - int readfd = mastermask; | | 236 | - int readfd = mastermask; |
208 | + fd_set readfd = mastermask; | | 237 | + fd_set readfd = mastermask; |
209 | int r; | | 238 | int r; |
210 | int nbyte; | | 239 | int nbyte; |
211 | int ncount = 10; | | 240 | int ncount = 10; |
212 | @@ -604,7 +622,7 @@ swallow_output() | | 241 | @@ -604,7 +622,7 @@ |
213 | while ( | | 242 | while ( |
214 | ncount-- && | | 243 | ncount-- && |
215 | select (selectnfds, &readfd, 0, 0, TIMEOUT_NOBLOCK) > 0 && | | 244 | select (selectnfds, &readfd, 0, 0, TIMEOUT_NOBLOCK) > 0 && |
216 | - readfd & mastermask | | 245 | - readfd & mastermask |
217 | + FD_ISSET(master, &mastermask) | | 246 | + FD_ISSET(master, &mastermask) |
218 | ) { | | 247 | ) { |
219 | nbyte = buf_read (master, output_buffer); | | 248 | nbyte = buf_read (master, output_buffer); |
220 | if (nbyte > 0) { | | 249 | if (nbyte > 0) { |
221 | @@ -636,21 +654,23 @@ swallow_output() | | 250 | @@ -636,21 +654,23 @@ |
222 | #include <sys/m_wait.h> | | 251 | #include <sys/m_wait.h> |
223 | #endif | | 252 | #endif |
224 | | | 253 | |
225 | -catchsig() | | 254 | -catchsig() |
226 | +void | | 255 | +void |
227 | +catchsig(n) | | 256 | +catchsig(n) |
228 | + int n; | | 257 | + int n; |
229 | { | | 258 | { |
230 | - union wait status; | | 259 | - union wait status; |
231 | + int status; | | 260 | + int status; |
232 | struct rusage ru; | | 261 | struct rusage ru; |
233 | | | 262 | |
234 | if (wait3 (&status, WNOHANG | WUNTRACED, &ru) != child_pid) | | 263 | if (wait3 (&status, WNOHANG | WUNTRACED, &ru) != child_pid) |
| @@ -236,27 +265,27 @@ $NetBSD: patch-aj,v 1.9 2006/01/17 21:23 | | | @@ -236,27 +265,27 @@ $NetBSD: patch-aj,v 1.9 2006/01/17 21:23 |
236 | if (WIFSTOPPED (status) /* || WIFSIGNALED (status) */) { | | 265 | if (WIFSTOPPED (status) /* || WIFSIGNALED (status) */) { |
237 | if (debug) { | | 266 | if (debug) { |
238 | - message ("Child has sttoped!!\n"); | | 267 | - message ("Child has sttoped!!\n"); |
239 | + message ("Child has stopped!!\n"); | | 268 | + message ("Child has stopped!!\n"); |
240 | } | | 269 | } |
241 | suspend (); | | 270 | suspend (); |
242 | return; | | 271 | return; |
243 | } | | 272 | } |
244 | - terminate (); | | 273 | - terminate (); |
245 | + terminate (WEXITSTATUS(status)); | | 274 | + terminate (WEXITSTATUS(status)); |
246 | } | | 275 | } |
247 | | | 276 | |
248 | exec_to_command(argv) | | 277 | exec_to_command(argv) |
249 | @@ -675,13 +695,37 @@ exec_to_command(argv) | | 278 | @@ -675,13 +695,37 @@ |
250 | dup2 (slave, 2); | | 279 | dup2 (slave, 2); |
251 | (void) close (slave); | | 280 | (void) close (slave); |
252 | | | 281 | |
253 | +#ifdef TERMIOS | | 282 | +#ifdef TERMIOS |
254 | + tcsetattr(0, TCSANOW, &slave_ttymode); | | 283 | + tcsetattr(0, TCSANOW, &slave_ttymode); |
255 | +#elif defined(TIOCSETN) | | 284 | +#elif defined(TIOCSETN) |
256 | ioctl (0, TIOCSETN, (char *) & slave_ttymode); | | 285 | ioctl (0, TIOCSETN, (char *) & slave_ttymode); |
257 | - | | 286 | - |
258 | +#endif | | 287 | +#endif |
259 | execvp (*argv, argv, 0); | | 288 | execvp (*argv, argv, 0); |
260 | perror (*argv); | | 289 | perror (*argv); |
261 | exit (1); | | 290 | exit (1); |
262 | } | | 291 | } |
| @@ -275,64 +304,64 @@ $NetBSD: patch-aj,v 1.9 2006/01/17 21:23 | | | @@ -275,64 +304,64 @@ $NetBSD: patch-aj,v 1.9 2006/01/17 21:23 |
275 | + master_ttymode.c_cc[VMIN] = 1; | | 304 | + master_ttymode.c_cc[VMIN] = 1; |
276 | + master_ttymode.c_cc[VTIME] = 0; | | 305 | + master_ttymode.c_cc[VTIME] = 0; |
277 | + slave_ttymode.c_lflag &= ~(ECHO|ECHOE|ECHOK); | | 306 | + slave_ttymode.c_lflag &= ~(ECHO|ECHOE|ECHOK); |
278 | + slave_ttymode.c_iflag &= ~(ICRNL); | | 307 | + slave_ttymode.c_iflag &= ~(ICRNL); |
279 | + slave_ttymode.c_oflag &= ~(ONLCR); | | 308 | + slave_ttymode.c_oflag &= ~(ONLCR); |
280 | + tcsetattr(0, TCSANOW, &master_ttymode); | | 309 | + tcsetattr(0, TCSANOW, &master_ttymode); |
281 | +} | | 310 | +} |
282 | + | | 311 | + |
283 | +#elif defined(TIOCSETN) | | 312 | +#elif defined(TIOCSETN) |
284 | + | | 313 | + |
285 | fix_tty() | | 314 | fix_tty() |
286 | { | | 315 | { |
287 | struct tchars tcbuf; | | 316 | struct tchars tcbuf; |
288 | @@ -719,6 +763,7 @@ fix_tty() | | 317 | @@ -719,6 +763,7 @@ |
289 | ioctl (0, TIOCSETC, (char *) & tcbuf); | | 318 | ioctl (0, TIOCSETC, (char *) & tcbuf); |
290 | ioctl (0, TIOCSLTC, (char *) & lcbuf); | | 319 | ioctl (0, TIOCSLTC, (char *) & lcbuf); |
291 | } | | 320 | } |
292 | +#endif | | 321 | +#endif |
293 | | | 322 | |
294 | kill_process() | | 323 | kill_process() |
295 | { | | 324 | { |
296 | @@ -727,9 +772,10 @@ kill_process() | | 325 | @@ -727,9 +772,10 @@ |
297 | (void) killpg (child_pid, SIGTERM); | | 326 | (void) killpg (child_pid, SIGTERM); |
298 | } | | 327 | } |
299 | | | 328 | |
300 | -terminate() | | 329 | -terminate() |
301 | +void | | 330 | +void |
302 | +terminate(n) | | 331 | +terminate(n) |
303 | + int n; | | 332 | + int n; |
304 | { | | 333 | { |
305 | - extern int errno; | | 334 | - extern int errno; |
306 | | | 335 | |
307 | /* | | 336 | /* |
308 | * Save history if 'history-file' is set | | 337 | * Save history if 'history-file' is set |
309 | @@ -759,10 +805,14 @@ terminate() | | 338 | @@ -759,10 +805,14 @@ |
310 | if (killpg (child_pid, SIGKILL) < 0) | | 339 | if (killpg (child_pid, SIGKILL) < 0) |
311 | perror ("kill"); | | 340 | perror ("kill"); |
312 | | | 341 | |
313 | +#ifdef TERMIOS | | 342 | +#ifdef TERMIOS |
314 | + tcsetattr(0, TCSANOW, &initial_ttymode); | | 343 | + tcsetattr(0, TCSANOW, &initial_ttymode); |
315 | +#elif defined(TIOCSETN) | | 344 | +#elif defined(TIOCSETN) |
316 | ioctl (0, TIOCSETN, (char *) & initial_ttymode); | | 345 | ioctl (0, TIOCSETN, (char *) & initial_ttymode); |
317 | ioctl (0, TIOCSETC, (char *) & tchars_buf); | | 346 | ioctl (0, TIOCSETC, (char *) & tchars_buf); |
318 | ioctl (0, TIOCSLTC, (char *) & ltchars_buf); | | 347 | ioctl (0, TIOCSLTC, (char *) & ltchars_buf); |
319 | - exit (0); | | 348 | - exit (0); |
320 | +#endif | | 349 | +#endif |
321 | + exit (n); | | 350 | + exit (n); |
322 | } | | 351 | } |
323 | | | 352 | |
324 | get_pty_master() | | 353 | get_pty_master() |
325 | @@ -775,6 +825,41 @@ get_pty_master() | | 354 | @@ -775,6 +825,41 @@ |
326 | master = 1; | | 355 | master = 1; |
327 | return; | | 356 | return; |
328 | } | | 357 | } |
329 | +#ifdef HAVE_PTMX | | 358 | +#ifdef HAVE_PTMX |
330 | + if ((master = open("/dev/ptmx", O_RDWR)) == -1) { | | 359 | + if ((master = open("/dev/ptmx", O_RDWR)) == -1) { |
331 | + perror ("Couldn't open pseudo tty"); | | 360 | + perror ("Couldn't open pseudo tty"); |
332 | + kill_process (); | | 361 | + kill_process (); |
333 | + exit (1); | | 362 | + exit (1); |
334 | + } | | 363 | + } |
335 | + if (grantpt (master) == -1) { | | 364 | + if (grantpt (master) == -1) { |
336 | + perror ("grantpt"); | | 365 | + perror ("grantpt"); |
337 | + kill_process (); | | 366 | + kill_process (); |
338 | + exit (1); | | 367 | + exit (1); |
| @@ -354,122 +383,122 @@ $NetBSD: patch-aj,v 1.9 2006/01/17 21:23 | | | @@ -354,122 +383,122 @@ $NetBSD: patch-aj,v 1.9 2006/01/17 21:23 |
354 | + if ((ptr = ptsname (master)) == NULL) { | | 383 | + if ((ptr = ptsname (master)) == NULL) { |
355 | + perror ("ptsname"); | | 384 | + perror ("ptsname"); |
356 | + kill_process (); | | 385 | + kill_process (); |
357 | + exit (1); | | 386 | + exit (1); |
358 | + } | | 387 | + } |
359 | + (void)strncpy (slave_tty, ptr, sizeof(slave_tty)); | | 388 | + (void)strncpy (slave_tty, ptr, sizeof(slave_tty)); |
360 | + slave_tty[sizeof(slave_tty) - 1] = '\0'; | | 389 | + slave_tty[sizeof(slave_tty) - 1] = '\0'; |
361 | +#endif | | 390 | +#endif |
362 | + } | | 391 | + } |
363 | +#else | | 392 | +#else |
364 | for (c = 'p'; c <= 's'; c++) { | | 393 | for (c = 'p'; c <= 's'; c++) { |
365 | for (i = 0; i < 16; i++) { | | 394 | for (i = 0; i < 16; i++) { |
366 | sprintf (master_tty, "/dev/pty%c%x", c, i); | | 395 | sprintf (master_tty, "/dev/pty%c%x", c, i); |
367 | @@ -796,11 +881,16 @@ get_pty_master() | | 396 | @@ -796,11 +881,16 @@ |
368 | } | | 397 | } |
369 | | | 398 | |
370 | FOUND: | | 399 | FOUND: |
371 | +#endif | | 400 | +#endif |
372 | +#ifdef TERMIOS | | 401 | +#ifdef TERMIOS |
373 | + tcgetattr(0, &initial_ttymode); | | 402 | + tcgetattr(0, &initial_ttymode); |
374 | +#elif defined(TIOCSETN) | | 403 | +#elif defined(TIOCSETN) |
375 | ioctl (0, TIOCGETP, (char *) &initial_ttymode); | | 404 | ioctl (0, TIOCGETP, (char *) &initial_ttymode); |
376 | ioctl (0, TIOCGETC, (char *) &tchars_buf); | | 405 | ioctl (0, TIOCGETC, (char *) &tchars_buf); |
377 | ioctl (0, TIOCGETD, (char *) &line_desc); | | 406 | ioctl (0, TIOCGETD, (char *) &line_desc); |
378 | ioctl (0, TIOCGLTC, (char *) <chars_buf); | | 407 | ioctl (0, TIOCGLTC, (char *) <chars_buf); |
379 | ioctl (0, TIOCLGET, (char *) &lmode_buf); | | 408 | ioctl (0, TIOCLGET, (char *) &lmode_buf); |
380 | +#endif | | 409 | +#endif |
381 | | | 410 | |
382 | #ifdef TIOCGWINSZ | | 411 | #ifdef TIOCGWINSZ |
383 | { | | 412 | { |
384 | @@ -820,11 +910,15 @@ get_pty_master() | | 413 | @@ -820,11 +910,15 @@ |
385 | # if defined(TIOCKGETC) && defined(TIOCKSETC) | | 414 | # if defined(TIOCKGETC) && defined(TIOCKSETC) |
386 | ioctl (0, TIOCKGETC, (char *) &jtchars_buf); | | 415 | ioctl (0, TIOCKGETC, (char *) &jtchars_buf); |
387 | # endif | | 416 | # endif |
388 | -#endif KANJI | | 417 | -#endif KANJI |
389 | +#endif /* KANJI */ | | 418 | +#endif /* KANJI */ |
390 | | | 419 | |
391 | - stdinmask = 1 << fileno (stdin); | | 420 | - stdinmask = 1 << fileno (stdin); |
392 | - mastermask = 1 << master; | | 421 | - mastermask = 1 << master; |
393 | - selectmask = stdinmask | mastermask; | | 422 | - selectmask = stdinmask | mastermask; |
394 | + FD_ZERO(&stdinmask); | | 423 | + FD_ZERO(&stdinmask); |
395 | + FD_ZERO(&mastermask); | | 424 | + FD_ZERO(&mastermask); |
396 | + FD_ZERO(&selectmask); | | 425 | + FD_ZERO(&selectmask); |
397 | + FD_SET(fileno(stdin), &stdinmask); | | 426 | + FD_SET(fileno(stdin), &stdinmask); |
398 | + FD_SET(master, &mastermask); | | 427 | + FD_SET(master, &mastermask); |
399 | + FD_SET(fileno(stdin), &selectmask); | | 428 | + FD_SET(fileno(stdin), &selectmask); |
400 | + FD_SET(master, &selectmask); | | 429 | + FD_SET(master, &selectmask); |
401 | selectnfds = max (fileno(stdin), master) + 1; | | 430 | selectnfds = max (fileno(stdin), master) + 1; |
402 | | | 431 | |
403 | return; | | 432 | return; |
404 | @@ -838,11 +932,20 @@ get_pty_slave() | | 433 | @@ -838,11 +932,20 @@ |
405 | perror (slave_tty); | | 434 | perror (slave_tty); |
406 | exit (1); | | 435 | exit (1); |
407 | } | | 436 | } |
408 | + if (setsid() == -1) | | 437 | + if (setsid() == -1) |
409 | + perror ("setsid"); | | 438 | + perror ("setsid"); |
410 | + if (ioctl (slave, TIOCSCTTY, 1) == -1) | | 439 | + if (ioctl (slave, TIOCSCTTY, 1) == -1) |
411 | + perror ("ioctl"); | | 440 | + perror ("ioctl"); |
412 | + | | 441 | + |
413 | +#ifdef TERMIOS | | 442 | +#ifdef TERMIOS |
414 | + tcsetattr(slave, TCSANOW, &initial_ttymode); | | 443 | + tcsetattr(slave, TCSANOW, &initial_ttymode); |
415 | +#elif defined(TIOCSETN) | | 444 | +#elif defined(TIOCSETN) |
416 | ioctl (slave, TIOCSETN, (char *) &initial_ttymode); | | 445 | ioctl (slave, TIOCSETN, (char *) &initial_ttymode); |
417 | ioctl (slave, TIOCSETC, (char *) &tchars_buf); | | 446 | ioctl (slave, TIOCSETC, (char *) &tchars_buf); |
418 | ioctl (slave, TIOCSLTC, (char *) <chars_buf); | | 447 | ioctl (slave, TIOCSLTC, (char *) <chars_buf); |
419 | ioctl (slave, TIOCLSET, (char *) &lmode_buf); | | 448 | ioctl (slave, TIOCLSET, (char *) &lmode_buf); |
420 | ioctl (slave, TIOCSETD, (char *) &line_desc); | | 449 | ioctl (slave, TIOCSETD, (char *) &line_desc); |
421 | +#endif | | 450 | +#endif |
422 | | | 451 | |
423 | #ifdef KANJI | | 452 | #ifdef KANJI |
424 | # if defined(TIOCKGET) && defined(TIOCKSET) | | 453 | # if defined(TIOCKGET) && defined(TIOCKSET) |
425 | @@ -851,7 +954,7 @@ get_pty_slave() | | 454 | @@ -851,7 +954,7 @@ |
426 | # if defined(TIOCKGETC) && defined(TIOCKSETC) | | 455 | # if defined(TIOCKGETC) && defined(TIOCKSETC) |
427 | ioctl (slave, TIOCKSETC, (char *) &jtchars_buf); | | 456 | ioctl (slave, TIOCKSETC, (char *) &jtchars_buf); |
428 | # endif | | 457 | # endif |
429 | -#endif KANJI | | 458 | -#endif KANJI |
430 | +#endif /* KANJI */ | | 459 | +#endif /* KANJI */ |
431 | | | 460 | |
432 | #ifdef TIOCSWINSZ | | 461 | #ifdef TIOCSWINSZ |
433 | { | | 462 | { |
434 | @@ -866,18 +969,20 @@ get_pty_slave() | | 463 | @@ -866,18 +969,20 @@ |
435 | | | 464 | |
436 | recover_tty() | | 465 | recover_tty() |
437 | { | | 466 | { |
438 | - | | 467 | - |
439 | +#ifdef TERMIOS | | 468 | +#ifdef TERMIOS |
440 | + tcsetattr(0, TCSANOW, &initial_ttymode); | | 469 | + tcsetattr(0, TCSANOW, &initial_ttymode); |
441 | +#elif defined(TIOCSETN) | | 470 | +#elif defined(TIOCSETN) |
442 | ioctl (0, TIOCSETN, (char *) & initial_ttymode); | | 471 | ioctl (0, TIOCSETN, (char *) & initial_ttymode); |
443 | ioctl (0, TIOCSETC, (char *) & tchars_buf); | | 472 | ioctl (0, TIOCSETC, (char *) & tchars_buf); |
444 | ioctl (0, TIOCSLTC, (char *) & ltchars_buf); | | 473 | ioctl (0, TIOCSLTC, (char *) & ltchars_buf); |
445 | +#endif | | 474 | +#endif |
446 | } | | 475 | } |
447 | | | 476 | |
448 | suspend() | | 477 | suspend() |
449 | { | | 478 | { |
450 | long pid; | | 479 | long pid; |
451 | - void (*func) (); | | 480 | - void (*func) (); |
452 | + void (*func) __P((int)); | | 481 | + void (*func) __P((int)); |
453 | int omask; | | 482 | int omask; |
454 | - extern int errno; | | 483 | - extern int errno; |
455 | | | 484 | |
456 | pid = getpid (); | | 485 | pid = getpid (); |
457 | /* reset signal handler so kill below stops us */ | | 486 | /* reset signal handler so kill below stops us */ |
458 | @@ -890,7 +995,7 @@ suspend() | | 487 | @@ -890,7 +995,7 @@ |
459 | | | 488 | |
460 | if (kill (child_pid, SIGCONT) < 0 && errno == ESRCH) { | | 489 | if (kill (child_pid, SIGCONT) < 0 && errno == ESRCH) { |
461 | printf ("Where my child has gone?!\n"); | | 490 | printf ("Where my child has gone?!\n"); |
462 | - terminate (); | | 491 | - terminate (); |
463 | + terminate (1); | | 492 | + terminate (1); |
464 | } | | 493 | } |
465 | killpg (child_pid, SIGCONT); | | 494 | killpg (child_pid, SIGCONT); |
466 | kill (0, SIGCONT); | | 495 | kill (0, SIGCONT); |
467 | @@ -933,7 +1038,7 @@ usageAndExit() | | 496 | @@ -933,7 +1038,7 @@ |
468 | /* | | 497 | /* |
469 | * Propagate window size changes to the slave tty. | | 498 | * Propagate window size changes to the slave tty. |
470 | */ | | 499 | */ |
471 | -sigwinch() | | 500 | -sigwinch() |
472 | +sigwinch(int num) | | 501 | +sigwinch(int num) |
473 | { | | 502 | { |
474 | #ifdef TIOCGWINSZ /* 4.3BSD */ | | 503 | #ifdef TIOCGWINSZ /* 4.3BSD */ |
475 | struct winsize win; | | 504 | struct winsize win; |