428
|
1 /* Interfaces to system-dependent kernel and library entries.
|
|
2 Copyright (C) 1985-1988, 1992-1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Tinker Systems.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: FSF 19.30 except for some Windows-NT crap. */
|
|
23
|
|
24 /* Substantially cleaned up by Ben Wing, Dec. 1994 / Jan. 1995. */
|
|
25
|
|
26 /* In this file, open, read and write refer to the system calls,
|
|
27 not our sugared interfaces sys_open, sys_read and sys_write.
|
|
28 */
|
|
29
|
|
30 #define DONT_ENCAPSULATE
|
|
31
|
|
32 #include <config.h>
|
|
33
|
442
|
34 #ifdef WIN32_NATIVE
|
|
35 #ifdef MINGW
|
462
|
36 #include <mingw/process.h>
|
440
|
37 #else
|
428
|
38 /* <process.h> should not conflict with "process.h", as per ANSI definition.
|
440
|
39 This is not true with visual c though. The trick below works with
|
|
40 VC4.2b, 5.0 and 6.0. It assumes that VC is installed in a kind of
|
|
41 standard way, so include path ends with /include.
|
428
|
42
|
|
43 Unfortunately, this must go before lisp.h, since process.h defines abort()
|
|
44 which will conflict with the macro defined in lisp.h
|
|
45 */
|
|
46 #include <../include/process.h>
|
442
|
47 #endif /* MINGW */
|
|
48 #endif /* WIN32_NATIVE */
|
428
|
49
|
|
50 #include "lisp.h"
|
|
51
|
|
52 /* ------------------------------- */
|
|
53 /* basic includes */
|
|
54 /* ------------------------------- */
|
|
55
|
|
56 #ifdef HAVE_TTY
|
|
57 #include "console-tty.h"
|
|
58 #else
|
|
59 #include "syssignal.h"
|
|
60 #include "systty.h"
|
|
61 #endif /* HAVE_TTY */
|
|
62
|
|
63 #include "console-stream.h"
|
|
64
|
|
65 #include "buffer.h"
|
|
66 #include "events.h"
|
|
67 #include "frame.h"
|
|
68 #include "redisplay.h"
|
|
69 #include "process.h"
|
|
70 #include "sysdep.h"
|
|
71 #include "window.h"
|
|
72
|
|
73 #include <setjmp.h>
|
|
74 #ifdef HAVE_LIBGEN_H /* Must come before sysfile.h */
|
|
75 #include <libgen.h>
|
|
76 #endif
|
|
77 #include "sysfile.h"
|
|
78 #include "syswait.h"
|
|
79 #include "sysdir.h"
|
|
80 #include "systime.h"
|
442
|
81 #if defined(WIN32_NATIVE) || defined(CYGWIN)
|
428
|
82 #include "syssignal.h"
|
|
83 #endif
|
442
|
84
|
|
85 #include "sysproc.h"
|
|
86
|
|
87 #ifndef WIN32_NATIVE
|
428
|
88 #include <sys/times.h>
|
|
89 #endif
|
|
90
|
442
|
91 #ifdef WIN32_NATIVE
|
428
|
92 #include <sys/utime.h>
|
|
93 #include "ntheap.h"
|
442
|
94 #include "nt.h"
|
428
|
95 #endif
|
|
96
|
|
97 /* ------------------------------- */
|
|
98 /* TTY definitions */
|
|
99 /* ------------------------------- */
|
|
100
|
|
101 #ifdef USG
|
|
102 #include <sys/utsname.h>
|
|
103 #if defined (TIOCGWINSZ) || defined (ISC4_0)
|
|
104 #ifdef NEED_SIOCTL
|
|
105 #include <sys/sioctl.h>
|
|
106 #endif
|
|
107 #ifdef NEED_PTEM_H
|
|
108 #include <sys/stream.h>
|
|
109 #include <sys/ptem.h>
|
|
110 #endif
|
|
111 #endif /* TIOCGWINSZ or ISC4_0 */
|
|
112 #endif /* USG */
|
|
113
|
|
114 /* LPASS8 is new in 4.3, and makes cbreak mode provide all 8 bits. */
|
|
115 #ifndef LPASS8
|
|
116 #define LPASS8 0
|
|
117 #endif
|
|
118
|
|
119 #ifndef HAVE_H_ERRNO
|
|
120 int h_errno;
|
|
121 #endif
|
|
122
|
|
123 #ifdef HAVE_TTY
|
|
124
|
|
125 static int baud_convert[] =
|
|
126 #ifdef BAUD_CONVERT
|
|
127 BAUD_CONVERT;
|
|
128 #else
|
|
129 {
|
|
130 0, 50, 75, 110, 135, 150, 200, 300, 600, 1200,
|
|
131 1800, 2400, 4800, 9600, 19200, 38400
|
|
132 };
|
|
133 #endif
|
|
134
|
|
135 #endif
|
|
136
|
|
137 #ifdef AIXHFT
|
|
138 static void hft_init (struct console *c);
|
|
139 static void hft_reset (struct console *c);
|
|
140 #include <sys/termio.h>
|
|
141 #endif
|
|
142
|
|
143
|
|
144 /************************************************************************/
|
|
145 /* subprocess control */
|
|
146 /************************************************************************/
|
|
147
|
|
148 #ifdef HAVE_TTY
|
|
149
|
|
150 #ifdef SIGTSTP
|
|
151
|
|
152 /* Arrange for character C to be read as the next input from
|
|
153 the terminal. */
|
|
154 void
|
|
155 stuff_char (struct console *con, int c)
|
|
156 {
|
|
157 int input_fd;
|
|
158
|
|
159 assert (CONSOLE_TTY_P (con));
|
|
160 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
161 /* Should perhaps error if in batch mode */
|
|
162 #ifdef TIOCSTI
|
|
163 ioctl (input_fd, TIOCSTI, &c);
|
|
164 #else /* no TIOCSTI */
|
|
165 error ("Cannot stuff terminal input characters in this version of Unix.");
|
|
166 #endif /* no TIOCSTI */
|
|
167 }
|
|
168
|
|
169 #endif /* SIGTSTP */
|
|
170
|
|
171 #endif /* HAVE_TTY */
|
|
172
|
|
173 void
|
|
174 set_exclusive_use (int fd)
|
|
175 {
|
|
176 #ifdef FIOCLEX
|
|
177 ioctl (fd, FIOCLEX, 0);
|
|
178 #endif
|
|
179 /* Ok to do nothing if this feature does not exist */
|
|
180 }
|
|
181
|
|
182 void
|
|
183 set_descriptor_non_blocking (int fd)
|
|
184 {
|
|
185 /* Stride people say it's a mystery why this is needed
|
|
186 as well as the O_NDELAY, but that it fails without this. */
|
|
187 /* For AIX: Apparently need this for non-blocking reads on sockets.
|
|
188 It seems that O_NONBLOCK applies only to FIFOs? From
|
|
189 lowry@watson.ibm.com (Andy Lowry). */
|
|
190 /* #### Should this be conditionalized on FIONBIO? */
|
|
191 #if defined (STRIDE) || (defined (pfa) && defined (HAVE_PTYS)) || defined (AIX)
|
|
192 {
|
|
193 int one = 1;
|
|
194 ioctl (fd, FIONBIO, &one);
|
|
195 }
|
|
196 #endif
|
|
197
|
|
198 #ifdef F_SETFL
|
|
199 fcntl (fd, F_SETFL, O_NONBLOCK);
|
|
200 #endif
|
|
201 }
|
|
202
|
|
203 #if defined (NO_SUBPROCESSES)
|
|
204
|
|
205 #ifdef BSD
|
|
206 void
|
|
207 wait_without_blocking (void)
|
|
208 {
|
|
209 wait3 (0, WNOHANG | WUNTRACED, 0);
|
|
210 synch_process_alive = 0;
|
|
211 }
|
|
212 #endif /* BSD */
|
|
213
|
|
214 #endif /* NO_SUBPROCESSES */
|
|
215
|
|
216
|
442
|
217 #ifdef WIN32_NATIVE
|
432
|
218 void wait_for_termination (HANDLE pHandle)
|
|
219 #else
|
|
220 void wait_for_termination (int pid)
|
|
221 #endif
|
428
|
222 {
|
|
223 /* #### With the new improved SIGCHLD handling stuff, there is much
|
|
224 less danger of race conditions and some of the comments below
|
|
225 don't apply. This should be updated. */
|
|
226
|
|
227 #if defined (NO_SUBPROCESSES)
|
|
228 while (1)
|
|
229 {
|
|
230 /* No need to be tricky like below; we can just call wait(). */
|
|
231 /* #### should figure out how to write a wait_allowing_quit().
|
|
232 Since hardly any systems don't have subprocess support,
|
|
233 however, there doesn't seem to be much point. */
|
|
234 if (wait (0) == pid)
|
|
235 return;
|
|
236 }
|
|
237 #elif defined (HAVE_WAITPID)
|
|
238 /* Note that, whenever any subprocess terminates (asynch. or synch.),
|
|
239 the SIGCHLD handler will be called and it will call wait(). Thus
|
|
240 we cannot just call wait() ourselves, and we can't block SIGCHLD
|
|
241 and then call wait(), because then if an asynch. process dies
|
|
242 while we're waiting for our synch. process, Emacs will never
|
|
243 notice that the asynch. process died.
|
|
244
|
|
245 So, the general approach we take is to repeatedly block until a
|
|
246 signal arrives, and then check if our process died using kill
|
|
247 (pid, 0). (We could also check the value of `synch_process_alive',
|
|
248 since the SIGCHLD handler will reset that and we know that we're
|
|
249 only being called on synchronous processes, but this approach is
|
|
250 safer. I don't trust the proper delivery of SIGCHLD.
|
|
251
|
|
252 Note also that we cannot use any form of waitpid(). A loop with
|
|
253 WNOHANG will chew up CPU time; better to use sleep(). A loop
|
|
254 without WNOWAIT will screw up the SIGCHLD handler (actually this
|
|
255 is not true, if you duplicate the exit-status-reaping code; see
|
|
256 below). A loop with WNOWAIT will result in a race condition if
|
|
257 the process terminates between the process-status check and the
|
|
258 call to waitpid(). */
|
|
259
|
|
260 /* Formerly, immediate_quit was set around this function call, but
|
|
261 that could lead to problems if the QUIT happened when SIGCHLD was
|
|
262 blocked -- it would remain blocked. Yet another reason why
|
|
263 immediate_quit is a bad idea. In any case, there is no reason to
|
|
264 resort to this because either the SIGIO or the SIGALRM will stop
|
|
265 the block in EMACS_WAIT_FOR_SIGNAL(). */
|
|
266
|
|
267 /* Apparently there are bugs on some systems with the second method
|
|
268 used below (the EMACS_BLOCK_SIGNAL method), whereby zombie
|
|
269 processes get left around. It appears in those cases that the
|
|
270 SIGCHLD handler is never getting invoked. It's not clear whether
|
|
271 this is an Emacs bug or a kernel bug or both: on HPUX this
|
|
272 problem is observed only with XEmacs, but under Solaris 2.4 all
|
|
273 sorts of different programs have problems with zombies. The
|
|
274 method we use here does not require a working SIGCHLD (but will
|
|
275 not break if it is working), and should be safe. */
|
|
276 /*
|
|
277 We use waitpid(), contrary to the remarks above. There is no
|
|
278 race condition, because the three situations when sigchld_handler
|
|
279 is invoked should be handled OK:
|
|
280
|
|
281 - handler invoked before waitpid(): In this case, subprocess
|
|
282 status will be set by sigchld_handler. waitpid() here will
|
|
283 return -1 with errno set to ECHILD, which is a valid exit
|
|
284 condition.
|
|
285
|
|
286 - handler invoked during waitpid(): as above, except that errno
|
|
287 here will be set to EINTR. This will cause waitpid() to be
|
|
288 called again, and this time it will exit with ECHILD.
|
|
289
|
|
290 - handler invoked after waitpid(): The following code will reap
|
|
291 the subprocess. In the handler, wait() will return -1 because
|
|
292 there is no child to reap, and the handler will exit without
|
|
293 modifying child subprocess status. */
|
|
294 int ret, status;
|
|
295
|
|
296 /* Because the SIGCHLD handler can potentially reap the synchronous
|
|
297 subprocess, we should take care of that. */
|
|
298
|
|
299 /* Will stay in the do loop as long as:
|
|
300 1. Process is alive
|
|
301 2. Ctrl-G is not pressed */
|
|
302 do
|
|
303 {
|
|
304 QUIT;
|
|
305 ret = waitpid (pid, &status, 0);
|
|
306 /* waitpid returns 0 if the process is still alive. */
|
|
307 }
|
|
308 while (ret == 0 || (ret == -1 && errno == EINTR));
|
|
309
|
|
310 if (ret == pid) /* Success */
|
|
311 /* Set synch process globals. This is can also happen
|
|
312 in sigchld_handler, and that code is duplicated. */
|
|
313 {
|
|
314 synch_process_alive = 0;
|
|
315 if (WIFEXITED (status))
|
|
316 synch_process_retcode = WEXITSTATUS (status);
|
|
317 else if (WIFSIGNALED (status))
|
|
318 synch_process_death = signal_name (WTERMSIG (status));
|
|
319 }
|
|
320 /* On exiting the loop, ret will be -1, with errno set to ECHILD if
|
|
321 the child has already been reaped, e.g. in the signal handler. */
|
|
322
|
|
323 /* Otherwise, we've had some error condition here.
|
|
324 Per POSIX, the only other possibilities are:
|
|
325 - EFAULT (bus error accessing arg 2) or
|
|
326 - EINVAL (incorrect arguments),
|
|
327 which are both program bugs.
|
|
328
|
|
329 Since implementations may add their own error indicators on top,
|
|
330 we ignore it by default. */
|
442
|
331 #elif defined (WIN32_NATIVE)
|
432
|
332 int ret = 0, status = 0;
|
|
333 if (pHandle == NULL)
|
|
334 {
|
|
335 warn_when_safe (Qprocess, Qwarning, "Cannot wait for unknown process to terminate");
|
|
336 return;
|
|
337 }
|
|
338 do
|
|
339 {
|
|
340 QUIT;
|
|
341 ret = WaitForSingleObject(pHandle, 100);
|
|
342 }
|
|
343 while (ret == WAIT_TIMEOUT);
|
|
344 if (ret == WAIT_FAILED)
|
|
345 {
|
|
346 warn_when_safe (Qprocess, Qwarning, "waiting for process failed");
|
|
347 }
|
|
348 if (ret == WAIT_ABANDONED)
|
|
349 {
|
|
350 warn_when_safe (Qprocess, Qwarning,
|
|
351 "process to wait for has been abandoned");
|
|
352 }
|
|
353 if (ret == WAIT_OBJECT_0)
|
|
354 {
|
|
355 ret = GetExitCodeProcess(pHandle, &status);
|
|
356 if (ret)
|
|
357 {
|
|
358 synch_process_alive = 0;
|
|
359 synch_process_retcode = status;
|
|
360 }
|
|
361 else
|
|
362 {
|
|
363 /* GetExitCodeProcess() didn't return a valid exit status,
|
|
364 nothing to do. APA */
|
|
365 warn_when_safe (Qprocess, Qwarning,
|
|
366 "failure to obtain process exit value");
|
|
367 }
|
|
368 }
|
440
|
369 if (pHandle != NULL && !CloseHandle(pHandle))
|
432
|
370 {
|
|
371 warn_when_safe (Qprocess, Qwarning,
|
|
372 "failure to close unknown process");
|
|
373 }
|
428
|
374 #elif defined (EMACS_BLOCK_SIGNAL) && !defined (BROKEN_WAIT_FOR_SIGNAL) && defined (SIGCHLD)
|
|
375 while (1)
|
|
376 {
|
|
377 static int wait_debugging = 0; /* Set nonzero to make following
|
|
378 function work under dbx (at least for bsd). */
|
|
379 QUIT;
|
|
380 if (wait_debugging)
|
|
381 return;
|
|
382
|
|
383 EMACS_BLOCK_SIGNAL (SIGCHLD);
|
|
384 /* Block SIGCHLD from happening during this check,
|
|
385 to avoid race conditions. */
|
|
386 if (kill (pid, 0) < 0)
|
|
387 {
|
|
388 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
|
|
389 return;
|
|
390 }
|
|
391 else
|
|
392 /* WARNING: Whatever this macro does *must* not allow SIGCHLD
|
|
393 to happen between the time that it's reenabled and when we
|
|
394 begin to block. Otherwise we may end up blocking for a
|
|
395 signal that has already arrived and isn't coming again.
|
|
396 Can you say "race condition"?
|
|
397
|
|
398 I assume that the system calls sigpause() or sigsuspend()
|
|
399 to provide this atomicness. If you're getting hangs in
|
|
400 sigpause()/sigsuspend(), then your OS doesn't implement
|
|
401 this properly (this applies under hpux9, for example).
|
|
402 Try defining BROKEN_WAIT_FOR_SIGNAL. */
|
|
403 EMACS_WAIT_FOR_SIGNAL (SIGCHLD);
|
|
404 }
|
442
|
405 #else /* not HAVE_WAITPID and not WIN32_NATIVE and (not EMACS_BLOCK_SIGNAL or BROKEN_WAIT_FOR_SIGNAL) */
|
428
|
406 /* This approach is kind of cheesy but is guaranteed(?!) to work
|
|
407 for all systems. */
|
|
408 while (1)
|
|
409 {
|
|
410 QUIT;
|
|
411 if (kill (pid, 0) < 0)
|
|
412 return;
|
|
413 emacs_sleep (1);
|
|
414 }
|
|
415 #endif /* OS features */
|
|
416 }
|
|
417
|
|
418
|
|
419 #if !defined (NO_SUBPROCESSES)
|
|
420
|
|
421 /*
|
|
422 * flush any pending output
|
|
423 * (may flush input as well; it does not matter the way we use it)
|
|
424 */
|
|
425
|
|
426 void
|
|
427 flush_pending_output (int channel)
|
|
428 {
|
|
429 #ifdef HAVE_TERMIOS
|
|
430 /* If we try this, we get hit with SIGTTIN, because
|
|
431 the child's tty belongs to the child's pgrp. */
|
|
432 #elif defined (TCFLSH)
|
|
433 ioctl (channel, TCFLSH, 1);
|
|
434 #elif defined (TIOCFLUSH)
|
|
435 int zero = 0;
|
|
436 /* 3rd arg should be ignored
|
|
437 but some 4.2 kernels actually want the address of an int
|
|
438 and nonzero means something different. */
|
|
439 ioctl (channel, TIOCFLUSH, &zero);
|
|
440 #endif
|
|
441 }
|
|
442
|
442
|
443 #ifndef WIN32_NATIVE
|
428
|
444 /* Set up the terminal at the other end of a pseudo-terminal that
|
|
445 we will be controlling an inferior through.
|
|
446 It should not echo or do line-editing, since that is done
|
|
447 in Emacs. No padding needed for insertion into an Emacs buffer. */
|
|
448
|
|
449 void
|
|
450 child_setup_tty (int out)
|
|
451 {
|
|
452 struct emacs_tty s;
|
430
|
453 emacs_get_tty (out, &s);
|
428
|
454
|
|
455 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
|
|
456 assert (isatty(out));
|
|
457 s.main.c_oflag |= OPOST; /* Enable output postprocessing */
|
|
458 s.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL on output */
|
513
|
459
|
|
460 {
|
|
461 /* Disable all output delays. */
|
|
462 tcflag_t delay_mask = 0;
|
428
|
463 #ifdef NLDLY
|
513
|
464 delay_mask |= NLDLY;
|
|
465 #endif
|
|
466 #ifdef CRDLY
|
|
467 delay_mask |= CRDLY;
|
|
468 #endif
|
|
469 #ifdef TABDLY
|
|
470 delay_mask |= TABDLY; /* Also disables tab expansion (Posix). */
|
|
471 #endif
|
|
472 #ifdef BSDLY
|
|
473 delay_mask |= BSDLY;
|
|
474 #endif
|
|
475 #ifdef VTDLY
|
|
476 delay_mask |= VTDLY;
|
428
|
477 #endif
|
513
|
478 #ifdef FFDLY
|
|
479 delay_mask |= FFDLY;
|
|
480 #endif
|
|
481 s.main.c_oflag &= ~delay_mask;
|
|
482 }
|
|
483
|
|
484 #ifdef OXTABS
|
|
485 /* Posix defines the TAB3 value for TABDLY to mean: expand tabs to spaces.
|
|
486 On those systems tab expansion would be disabled by the above code.
|
|
487 BSD systems use an independent flag, OXTABS. */
|
|
488 s.main.c_oflag &= ~OXTABS; /* Disable tab expansion */
|
|
489 #endif
|
|
490
|
428
|
491 s.main.c_lflag &= ~ECHO; /* Disable echo */
|
|
492 s.main.c_lflag |= ISIG; /* Enable signals */
|
|
493 #ifdef IUCLC
|
|
494 s.main.c_iflag &= ~IUCLC; /* Disable downcasing on input. */
|
|
495 #endif
|
|
496 #ifdef OLCUC
|
|
497 s.main.c_oflag &= ~OLCUC; /* Disable upcasing on output. */
|
|
498 #endif
|
513
|
499
|
428
|
500 #if defined (CSIZE) && defined (CS8)
|
|
501 s.main.c_cflag = (s.main.c_cflag & ~CSIZE) | CS8; /* Don't strip 8th bit */
|
|
502 #endif
|
|
503 #ifdef ISTRIP
|
|
504 s.main.c_iflag &= ~ISTRIP; /* Don't strip 8th bit on input */
|
|
505 #endif
|
|
506 #if 0
|
|
507 /* Unnecessary as long as ICANON is set */
|
|
508 s.main.c_cc[VMIN] = 1; /* minimum number of characters to accept */
|
|
509 s.main.c_cc[VTIME] = 0; /* wait forever for at least 1 character */
|
|
510 #endif /* 0 */
|
|
511
|
|
512 s.main.c_lflag |= ICANON; /* Enable erase/kill and eof processing */
|
|
513 s.main.c_cc[VEOF] = 04; /* ensure that EOF is Control-D */
|
|
514 s.main.c_cc[VERASE] = _POSIX_VDISABLE; /* disable erase processing */
|
|
515 s.main.c_cc[VKILL] = _POSIX_VDISABLE; /* disable kill processing */
|
|
516
|
|
517 #ifdef HPUX
|
|
518 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
|
|
519 #endif /* HPUX */
|
|
520
|
|
521 #ifdef AIX
|
|
522 #ifndef IBMR2AIX
|
|
523 /* AIX enhanced edit loses NULs, so disable it. */
|
|
524 s.main.c_line = 0;
|
|
525 s.main.c_iflag &= ~ASCEDIT;
|
|
526 #endif /* IBMR2AIX */
|
|
527 /* Also, PTY overloads NUL and BREAK.
|
|
528 don't ignore break, but don't signal either, so it looks like NUL.
|
|
529 This really serves a purpose only if running in an XTERM window
|
|
530 or via TELNET or the like, but does no harm elsewhere. */
|
|
531 s.main.c_iflag &= ~IGNBRK;
|
|
532 s.main.c_iflag &= ~BRKINT;
|
|
533 #endif /* AIX */
|
|
534 #ifdef SIGNALS_VIA_CHARACTERS
|
|
535 /* TTY `special characters' are used in process_send_signal
|
|
536 so set them here to something useful. */
|
|
537 s.main.c_cc[VQUIT] = '\\'&037; /* Control-\ */
|
|
538 s.main.c_cc[VINTR] = 'C' &037; /* Control-C */
|
|
539 s.main.c_cc[VSUSP] = 'Z' &037; /* Control-Z */
|
|
540 #else /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
|
|
541 /* TTY `special characters' work better as signals, so disable
|
|
542 character forms */
|
|
543 s.main.c_cc[VQUIT] = _POSIX_VDISABLE;
|
|
544 s.main.c_cc[VINTR] = _POSIX_VDISABLE;
|
|
545 s.main.c_cc[VSUSP] = _POSIX_VDISABLE;
|
|
546 s.main.c_lflag &= ~ISIG;
|
|
547 #endif /* no TIOCGPGRP or no TIOCGLTC or no TIOCGETC */
|
|
548 s.main.c_cc[VEOL] = _POSIX_VDISABLE;
|
|
549 #if defined (CBAUD)
|
440
|
550 /* <mdiers> #### This is not portable. ###
|
428
|
551 POSIX does not specify CBAUD, and 4.4BSD does not have it.
|
|
552 Instead, POSIX suggests to use cfset{i,o}speed().
|
|
553 [cf. D. Lewine, POSIX Programmer's Guide, Chapter 8: Terminal
|
|
554 I/O, O'Reilly 1991] */
|
|
555 s.main.c_cflag = (s.main.c_cflag & ~CBAUD) | B9600; /* baud rate sanity */
|
|
556 #else
|
|
557 /* <mdiers> What to do upon failure? Just ignoring rc is probably
|
|
558 not acceptable, is it? */
|
|
559 if (cfsetispeed (&s.main, B9600) == -1) /* ignore */;
|
|
560 if (cfsetospeed (&s.main, B9600) == -1) /* ignore */;
|
|
561 #endif /* defined (CBAUD) */
|
|
562
|
|
563 #else /* not HAVE_TERMIO */
|
|
564
|
|
565 s.main.sg_flags &= ~(ECHO | CRMOD | ANYP | ALLDELAY | RAW | LCASE
|
|
566 | CBREAK | TANDEM);
|
|
567 s.main.sg_flags |= LPASS8;
|
|
568 s.main.sg_erase = 0377;
|
|
569 s.main.sg_kill = 0377;
|
|
570 s.lmode = LLITOUT | s.lmode; /* Don't strip 8th bit */
|
|
571
|
|
572 #endif /* not HAVE_TERMIO */
|
430
|
573 emacs_set_tty (out, &s, 0);
|
428
|
574
|
|
575 #ifdef RTU
|
|
576 {
|
|
577 int zero = 0;
|
|
578 ioctl (out, FIOASYNC, &zero);
|
|
579 }
|
|
580 #endif /* RTU */
|
|
581 }
|
442
|
582 #endif /* WIN32_NATIVE */
|
428
|
583
|
|
584 #endif /* not NO_SUBPROCESSES */
|
|
585
|
|
586
|
|
587 #if !defined (SIGTSTP) && !defined (USG_JOBCTRL)
|
|
588
|
|
589 #if defined(__STDC__) || defined(_MSC_VER)
|
|
590 #define SIG_PARAM_TYPE int
|
|
591 #else
|
|
592 #define SIG_PARAM_TYPE
|
|
593 #endif
|
|
594
|
|
595 /* Record a signal code and the handler for it. */
|
|
596 struct save_signal
|
|
597 {
|
|
598 int code;
|
|
599 SIGTYPE (*handler) (SIG_PARAM_TYPE);
|
|
600 };
|
|
601
|
|
602 static void
|
|
603 save_signal_handlers (struct save_signal *saved_handlers)
|
|
604 {
|
|
605 while (saved_handlers->code)
|
|
606 {
|
|
607 saved_handlers->handler
|
|
608 = (SIGTYPE (*) (SIG_PARAM_TYPE)) signal (saved_handlers->code, SIG_IGN);
|
|
609 saved_handlers++;
|
|
610 }
|
|
611 }
|
|
612
|
|
613 static void
|
|
614 restore_signal_handlers (struct save_signal *saved_handlers)
|
|
615 {
|
|
616 while (saved_handlers->code)
|
|
617 {
|
|
618 signal (saved_handlers->code, saved_handlers->handler);
|
|
619 saved_handlers++;
|
|
620 }
|
|
621 }
|
|
622
|
442
|
623 #ifdef WIN32_NATIVE
|
|
624
|
428
|
625 pid_t
|
|
626 sys_getpid (void)
|
|
627 {
|
|
628 return abs (getpid ());
|
|
629 }
|
442
|
630
|
|
631 #endif /* WIN32_NATIVE */
|
428
|
632
|
|
633 /* Fork a subshell. */
|
|
634 static void
|
|
635 sys_subshell (void)
|
|
636 {
|
442
|
637 #ifndef WIN32_NATIVE
|
428
|
638 int pid;
|
432
|
639 #endif
|
428
|
640 struct save_signal saved_handlers[5];
|
|
641 Lisp_Object dir;
|
|
642 unsigned char *str = 0;
|
|
643 int len;
|
|
644 struct gcpro gcpro1;
|
|
645
|
|
646 saved_handlers[0].code = SIGINT;
|
|
647 saved_handlers[1].code = SIGQUIT;
|
|
648 saved_handlers[2].code = SIGTERM;
|
|
649 #ifdef SIGIO
|
|
650 saved_handlers[3].code = SIGIO;
|
|
651 saved_handlers[4].code = 0;
|
|
652 #else
|
|
653 saved_handlers[3].code = 0;
|
|
654 #endif
|
|
655
|
|
656 /* Mentioning current_buffer->buffer would mean including buffer.h,
|
|
657 which somehow wedges the hp compiler. So instead... */
|
|
658
|
|
659 if (NILP (Fboundp (Qdefault_directory)))
|
|
660 goto xyzzy;
|
|
661 dir = Fsymbol_value (Qdefault_directory);
|
|
662 if (!STRINGP (dir))
|
|
663 goto xyzzy;
|
|
664
|
|
665 GCPRO1 (dir);
|
|
666 dir = Funhandled_file_name_directory (dir);
|
|
667 dir = expand_and_dir_to_file (dir, Qnil);
|
|
668 UNGCPRO;
|
|
669 str = (unsigned char *) alloca (XSTRING_LENGTH (dir) + 2);
|
|
670 len = XSTRING_LENGTH (dir);
|
|
671 memcpy (str, XSTRING_DATA (dir), len);
|
442
|
672 if (!IS_ANY_SEP (str[len - 1]))
|
|
673 str[len++] = DIRECTORY_SEP;
|
428
|
674 str[len] = 0;
|
|
675 xyzzy:
|
|
676
|
442
|
677 #ifndef WIN32_NATIVE
|
428
|
678 pid = fork ();
|
|
679
|
|
680 if (pid == -1)
|
|
681 error ("Can't spawn subshell");
|
|
682 if (pid == 0)
|
442
|
683 #endif /* not WIN32_NATIVE */
|
428
|
684 {
|
|
685 char *sh = 0;
|
|
686
|
|
687 if (sh == 0)
|
|
688 sh = (char *) egetenv ("SHELL");
|
|
689 if (sh == 0)
|
|
690 sh = "sh";
|
|
691
|
|
692 /* Use our buffer's default directory for the subshell. */
|
|
693 if (str)
|
|
694 sys_chdir (str);
|
|
695
|
442
|
696 #ifdef WIN32_NATIVE
|
|
697
|
|
698 /* Waits for process completion */
|
|
699 if (_spawnlp (_P_WAIT, sh, sh, NULL) != 0)
|
|
700 error ("Can't spawn subshell");
|
|
701 else
|
|
702 return; /* we're done, no need to wait for termination */
|
|
703 }
|
|
704
|
|
705 #else
|
|
706
|
|
707 #if !defined (NO_SUBPROCESSES)
|
428
|
708 close_process_descs (); /* Close Emacs's pipes/ptys */
|
|
709 #endif
|
|
710
|
|
711 #ifdef SET_EMACS_PRIORITY
|
|
712 if (emacs_priority != 0)
|
|
713 nice (-emacs_priority); /* Give the new shell the default priority */
|
|
714 #endif
|
|
715
|
|
716 execlp (sh, sh, 0);
|
|
717 write (1, "Can't execute subshell", 22);
|
|
718 _exit (1);
|
|
719 }
|
|
720
|
|
721 save_signal_handlers (saved_handlers);
|
|
722 synch_process_alive = 1;
|
|
723 wait_for_termination (pid);
|
|
724 restore_signal_handlers (saved_handlers);
|
442
|
725
|
|
726 #endif /* not WIN32_NATIVE */
|
|
727
|
428
|
728 }
|
|
729
|
|
730 #endif /* !defined (SIGTSTP) && !defined (USG_JOBCTRL) */
|
|
731
|
|
732
|
|
733
|
|
734 /* Suspend the Emacs process; give terminal to its superior. */
|
|
735 void
|
|
736 sys_suspend (void)
|
|
737 {
|
|
738 #if defined (SIGTSTP)
|
|
739 {
|
|
740 int pgrp = EMACS_GET_PROCESS_GROUP ();
|
|
741 EMACS_KILLPG (pgrp, SIGTSTP);
|
|
742 }
|
|
743
|
|
744 #elif defined (USG_JOBCTRL)
|
|
745 /* If you don't know what this is don't mess with it */
|
|
746 ptrace (0, 0, 0, 0); /* set for ptrace - caught by csh */
|
|
747 kill (getpid (), SIGQUIT);
|
|
748
|
|
749 #else /* No SIGTSTP or USG_JOBCTRL */
|
|
750
|
|
751 /* On a system where suspending is not implemented,
|
|
752 instead fork a subshell and let it talk directly to the terminal
|
|
753 while we wait. */
|
|
754 sys_subshell ();
|
|
755
|
|
756 #endif
|
|
757 }
|
|
758
|
|
759 /* Suspend a process if possible; give terminal to its superior. */
|
|
760 void
|
|
761 sys_suspend_process (int process)
|
|
762 {
|
|
763 /* I don't doubt that it is possible to suspend processes on
|
|
764 * VMS machines or thost that use USG_JOBCTRL,
|
|
765 * but I don't know how to do it, so...
|
|
766 */
|
|
767 #if defined (SIGTSTP)
|
|
768 kill(process, SIGTSTP);
|
|
769 #endif
|
|
770 }
|
|
771
|
|
772
|
|
773 /* Given FD, obtain pty buffer size. When no luck, a good guess is made,
|
442
|
774 so that the function works even when fd is not a pty. */
|
428
|
775
|
|
776 int
|
|
777 get_pty_max_bytes (int fd)
|
|
778 {
|
442
|
779 /* DEC OSF 4.0 fpathconf returns 255, but xemacs hangs on long shell
|
|
780 input lines if we return 253. 252 is OK!. So let's leave a bit
|
|
781 of slack for the newline that xemacs will insert, and for those
|
|
782 inevitable vendor off-by-one-or-two-or-three bugs. */
|
|
783 #define MAX_CANON_SLACK 10
|
|
784 #define SAFE_MAX_CANON (127 - MAX_CANON_SLACK)
|
428
|
785 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON)
|
442
|
786 {
|
|
787 int max_canon = fpathconf (fd, _PC_MAX_CANON);
|
|
788 #ifdef __hpux__
|
|
789 /* HP-UX 10.20 fpathconf returns 768, but this results in
|
|
790 truncated input lines, while 255 works. */
|
|
791 if (max_canon > 255) max_canon = 255;
|
428
|
792 #endif
|
442
|
793 return (max_canon < 0 ? SAFE_MAX_CANON :
|
|
794 max_canon > SAFE_MAX_CANON ? max_canon - MAX_CANON_SLACK :
|
|
795 max_canon);
|
|
796 }
|
|
797 #elif defined (_POSIX_MAX_CANON)
|
|
798 return (_POSIX_MAX_CANON > SAFE_MAX_CANON ?
|
|
799 _POSIX_MAX_CANON - MAX_CANON_SLACK :
|
|
800 _POSIX_MAX_CANON);
|
|
801 #else
|
|
802 return SAFE_MAX_CANON;
|
|
803 #endif
|
428
|
804 }
|
|
805
|
|
806 /* Figure out the eof character for the FD. */
|
|
807
|
|
808 Bufbyte
|
|
809 get_eof_char (int fd)
|
|
810 {
|
442
|
811 const Bufbyte ctrl_d = (Bufbyte) '\004';
|
428
|
812
|
|
813 if (!isatty (fd))
|
|
814 return ctrl_d;
|
|
815 #ifdef HAVE_TERMIOS
|
|
816 {
|
|
817 struct termios t;
|
|
818 tcgetattr (fd, &t);
|
|
819 #if 0
|
|
820 /* What is the following line designed to do??? -mrb */
|
442
|
821 if (strlen ((const char *) t.c_cc) < (unsigned int) (VEOF + 1))
|
428
|
822 return ctrl_d;
|
|
823 else
|
|
824 return (Bufbyte) t.c_cc[VEOF];
|
|
825 #endif
|
|
826 return t.c_cc[VEOF] == _POSIX_VDISABLE ? ctrl_d : (Bufbyte) t.c_cc[VEOF];
|
|
827 }
|
|
828 #else /* ! HAVE_TERMIOS */
|
|
829 /* On Berkeley descendants, the following IOCTL's retrieve the
|
|
830 current control characters. */
|
|
831 #if defined (TIOCGETC)
|
|
832 {
|
|
833 struct tchars c;
|
|
834 ioctl (fd, TIOCGETC, &c);
|
|
835 return (Bufbyte) c.t_eofc;
|
|
836 }
|
|
837 #else /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
|
|
838 /* On SYSV descendants, the TCGETA ioctl retrieves the current control
|
|
839 characters. */
|
|
840 #ifdef TCGETA
|
|
841 {
|
|
842 struct termio t;
|
|
843 ioctl (fd, TCGETA, &t);
|
442
|
844 if (strlen ((const char *) t.c_cc) < (unsigned int) (VINTR + 1))
|
428
|
845 return ctrl_d;
|
|
846 else
|
|
847 return (Bufbyte) t.c_cc[VINTR];
|
|
848 }
|
|
849 #else /* ! defined (TCGETA) */
|
|
850 /* Rather than complain, we'll just guess ^D, which is what
|
|
851 * earlier emacsen always used. */
|
|
852 return ctrl_d;
|
|
853 #endif /* ! defined (TCGETA) */
|
|
854 #endif /* ! defined (TIOCGETC) */
|
|
855 #endif /* ! defined (HAVE_TERMIOS) */
|
|
856 }
|
|
857
|
|
858 /* Set the logical window size associated with descriptor FD
|
|
859 to HEIGHT and WIDTH. This is used mainly with ptys. */
|
|
860
|
|
861 int
|
|
862 set_window_size (int fd, int height, int width)
|
|
863 {
|
|
864 #ifdef TIOCSWINSZ
|
|
865
|
|
866 /* BSD-style. */
|
|
867 struct winsize size;
|
|
868 size.ws_row = height;
|
|
869 size.ws_col = width;
|
|
870
|
|
871 if (ioctl (fd, TIOCSWINSZ, &size) == -1)
|
|
872 return 0; /* error */
|
|
873 else
|
|
874 return 1;
|
|
875
|
|
876 #elif defined (TIOCSSIZE)
|
|
877
|
|
878 /* SunOS - style. */
|
|
879 struct ttysize size;
|
|
880 size.ts_lines = height;
|
|
881 size.ts_cols = width;
|
|
882
|
|
883 if (ioctl (fd, TIOCGSIZE, &size) == -1)
|
|
884 return 0;
|
|
885 else
|
|
886 return 1;
|
|
887 #else
|
|
888 return -1;
|
|
889 #endif
|
|
890 }
|
|
891
|
|
892 #ifdef HAVE_PTYS
|
|
893
|
|
894 /* Set up the proper status flags for use of a pty. */
|
|
895
|
|
896 void
|
|
897 setup_pty (int fd)
|
|
898 {
|
442
|
899 /* I'm told that TIOCREMOTE does not mean control chars
|
428
|
900 "can't be sent" but rather that they don't have
|
|
901 input-editing or signaling effects.
|
|
902 That should be good, because we have other ways
|
|
903 to do those things in Emacs.
|
|
904 However, telnet mode seems not to work on 4.2.
|
|
905 So TIOCREMOTE is turned off now. */
|
|
906
|
|
907 /* Under hp-ux, if TIOCREMOTE is turned on, some calls
|
|
908 will hang. In particular, the "timeout" feature (which
|
|
909 causes a read to return if there is no data available)
|
|
910 does this. Also it is known that telnet mode will hang
|
|
911 in such a way that Emacs must be stopped (perhaps this
|
|
912 is the same problem).
|
|
913
|
|
914 If TIOCREMOTE is turned off, then there is a bug in
|
|
915 hp-ux which sometimes loses data. Apparently the
|
|
916 code which blocks the master process when the internal
|
|
917 buffer fills up does not work. Other than this,
|
|
918 though, everything else seems to work fine.
|
|
919
|
|
920 Since the latter lossage is more benign, we may as well
|
|
921 lose that way. -- cph */
|
|
922 #if defined (FIONBIO) && defined (SYSV_PTYS)
|
|
923 {
|
|
924 int on = 1;
|
|
925 ioctl (fd, FIONBIO, &on);
|
|
926 }
|
|
927 #endif
|
|
928 #ifdef IBMRTAIX
|
|
929 /* On AIX, the parent gets SIGHUP when a pty attached child dies. So, we */
|
|
930 /* ignore SIGHUP once we've started a child on a pty. Note that this may */
|
|
931 /* cause EMACS not to die when it should, i.e., when its own controlling */
|
|
932 /* tty goes away. I've complained to the AIX developers, and they may */
|
|
933 /* change this behavior, but I'm not going to hold my breath. */
|
|
934 signal (SIGHUP, SIG_IGN);
|
|
935 #endif
|
|
936 #ifdef TIOCPKT
|
|
937 /* In some systems (Linux through 2.0.0, at least), packet mode doesn't
|
|
938 get cleared when a pty is closed, so we need to clear it here.
|
|
939 Linux pre2.0.13 contained an attempted fix for this (from Ted Ts'o,
|
|
940 tytso@mit.edu), but apparently it messed up rlogind and telnetd, so he
|
|
941 removed the fix in pre2.0.14. - dkindred@cs.cmu.edu
|
|
942 */
|
|
943 {
|
|
944 int off = 0;
|
|
945 ioctl (fd, TIOCPKT, (char *)&off);
|
|
946 }
|
|
947 #endif
|
|
948 }
|
|
949 #endif /* HAVE_PTYS */
|
|
950
|
|
951
|
|
952 /************************************************************************/
|
|
953 /* TTY control */
|
|
954 /************************************************************************/
|
|
955
|
|
956 /* ------------------------------------------------------ */
|
|
957 /* get baud rate */
|
|
958 /* ------------------------------------------------------ */
|
|
959
|
|
960 /* It really makes more sense for the baud-rate to be console-specific
|
|
961 and not device-specific, but it's (at least potentially) used for output
|
|
962 decisions. */
|
|
963
|
|
964 void
|
|
965 init_baud_rate (struct device *d)
|
|
966 {
|
|
967 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
968 if (DEVICE_WIN_P (d) || DEVICE_STREAM_P (d))
|
|
969 {
|
|
970 DEVICE_BAUD_RATE (d) = 38400;
|
|
971 return;
|
|
972 }
|
|
973
|
|
974 #ifdef HAVE_TTY
|
|
975 assert (DEVICE_TTY_P (d));
|
|
976 {
|
|
977 int input_fd = CONSOLE_TTY_DATA (con)->infd;
|
442
|
978 #if defined (WIN32_NATIVE)
|
428
|
979 DEVICE_TTY_DATA (d)->ospeed = 15;
|
|
980 #elif defined (HAVE_TERMIOS)
|
|
981 struct termios sg;
|
|
982
|
|
983 sg.c_cflag = B9600;
|
|
984 tcgetattr (input_fd, &sg);
|
|
985 DEVICE_TTY_DATA (d)->ospeed = cfgetospeed (&sg);
|
|
986 # if defined (USE_GETOBAUD) && defined (getobaud)
|
|
987 /* m88k-motorola-sysv3 needs this (ghazi@noc.rutgers.edu) 9/1/94. */
|
|
988 if (DEVICE_TTY_DATA (d)->ospeed == 0)
|
|
989 DEVICE_TTY_DATA (d)->ospeed = getobaud (sg.c_cflag);
|
|
990 # endif
|
|
991 #elif defined (HAVE_TERMIO)
|
|
992 struct termio sg;
|
|
993
|
|
994 sg.c_cflag = B9600;
|
|
995 # ifdef HAVE_TCATTR
|
|
996 tcgetattr (input_fd, &sg);
|
|
997 # else
|
|
998 ioctl (input_fd, TCGETA, &sg);
|
|
999 # endif
|
|
1000 DEVICE_TTY_DATA (d)->ospeed = sg.c_cflag & CBAUD;
|
|
1001 #else /* neither TERMIOS nor TERMIO */
|
|
1002 struct sgttyb sg;
|
|
1003
|
|
1004 sg.sg_ospeed = B9600;
|
|
1005 if (ioctl (input_fd, TIOCGETP, &sg) < 0)
|
|
1006 abort ();
|
|
1007 DEVICE_TTY_DATA (d)->ospeed = sg.sg_ospeed;
|
|
1008 #endif
|
|
1009 }
|
|
1010
|
|
1011 DEVICE_BAUD_RATE (d) =
|
|
1012 (DEVICE_TTY_DATA (d)->ospeed < countof (baud_convert)
|
|
1013 ? baud_convert[DEVICE_TTY_DATA (d)->ospeed]
|
|
1014 : 9600);
|
|
1015
|
|
1016 if (DEVICE_BAUD_RATE (d) == 0)
|
|
1017 DEVICE_BAUD_RATE (d) = 1200;
|
|
1018 #endif /* HAVE_TTY */
|
|
1019 }
|
|
1020
|
|
1021
|
|
1022 /* ------------------------------------------------------ */
|
|
1023 /* SIGIO control */
|
|
1024 /* ------------------------------------------------------ */
|
|
1025
|
|
1026 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
|
|
1027
|
|
1028 static void
|
|
1029 init_sigio_on_device (struct device *d)
|
|
1030 {
|
|
1031 int filedesc = DEVICE_INFD (d);
|
|
1032
|
|
1033 #if defined (FIOSSAIOOWN)
|
|
1034 { /* HPUX stuff */
|
|
1035 int owner = getpid ();
|
|
1036 int ioctl_status;
|
|
1037 if (DEVICE_TTY_P (d))
|
|
1038 {
|
|
1039 ioctl_status = ioctl (filedesc, FIOGSAIOOWN,
|
|
1040 &DEVICE_OLD_FCNTL_OWNER (d));
|
|
1041 ioctl_status = ioctl (filedesc, FIOSSAIOOWN, &owner);
|
|
1042 }
|
|
1043 #ifdef HAVE_WINDOW_SYSTEM
|
|
1044 else if (!DEVICE_STREAM_P (d))
|
|
1045 {
|
|
1046 ioctl_status = ioctl (filedesc, SIOCGPGRP,
|
|
1047 &DEVICE_OLD_FCNTL_OWNER (d));
|
|
1048 ioctl_status = ioctl (filedesc, SIOCSPGRP, &owner);
|
|
1049 }
|
|
1050 #endif
|
|
1051 }
|
|
1052 #elif defined (F_SETOWN) && !defined (F_SETOWN_BUG)
|
|
1053 DEVICE_OLD_FCNTL_OWNER (d) = fcntl (filedesc, F_GETOWN, 0);
|
|
1054 # ifdef F_SETOWN_SOCK_NEG
|
|
1055 /* stdin is a socket here */
|
|
1056 fcntl (filedesc, F_SETOWN, -getpid ());
|
|
1057 # else
|
|
1058 fcntl (filedesc, F_SETOWN, getpid ());
|
|
1059 # endif
|
|
1060 #endif
|
|
1061 }
|
|
1062
|
|
1063 static void
|
|
1064 reset_sigio_on_device (struct device *d)
|
|
1065 {
|
|
1066 int filedesc = DEVICE_INFD (d);
|
|
1067
|
|
1068 #if defined (FIOSSAIOOWN)
|
|
1069 { /* HPUX stuff */
|
|
1070 int ioctl_status;
|
|
1071 if (DEVICE_TTY_P (d))
|
|
1072 {
|
|
1073 ioctl_status = ioctl (filedesc, FIOSSAIOOWN,
|
|
1074 &DEVICE_OLD_FCNTL_OWNER (d));
|
|
1075 }
|
|
1076 #ifdef HAVE_WINDOW_SYSTEM
|
|
1077 else if (!DEVICE_STREAM_P (d))
|
|
1078 {
|
|
1079 ioctl_status = ioctl (filedesc, SIOCSPGRP,
|
|
1080 &DEVICE_OLD_FCNTL_OWNER (d));
|
|
1081 }
|
|
1082 #endif
|
|
1083 }
|
|
1084 #elif defined (F_SETOWN) && !defined (F_SETOWN_BUG)
|
|
1085 fcntl (filedesc, F_SETOWN, DEVICE_OLD_FCNTL_OWNER (d));
|
|
1086 #endif
|
|
1087 }
|
|
1088
|
|
1089 static void
|
|
1090 request_sigio_on_device (struct device *d)
|
|
1091 {
|
|
1092 int filedesc = DEVICE_INFD (d);
|
|
1093
|
502
|
1094 /* NOTE: It appears that Linux has its own mechanism for requesting
|
|
1095 SIGIO, using the F_GETSIG and F_SETSIG commands to fcntl().
|
|
1096 These let you pick which signal you want sent (not just SIGIO),
|
|
1097 and if you do this, you get additional info which tells you which
|
|
1098 file descriptor has input ready on it. The man page says:
|
|
1099
|
|
1100 Using these mechanisms, a program can implement fully
|
|
1101 asynchronous I/O without using select(2) or poll(2) most
|
|
1102 of the time.
|
|
1103
|
|
1104 The use of O_ASYNC, F_GETOWN, F_SETOWN is specific to BSD
|
|
1105 and Linux. F_GETSIG and F_SETSIG are Linux-specific.
|
|
1106 POSIX has asynchronous I/O and the aio_sigevent structure
|
|
1107 to achieve similar things; these are also available in
|
|
1108 Linux as part of the GNU C Library (Glibc).
|
|
1109
|
|
1110 But it appears that Linux also supports O_ASYNC, so I see no
|
|
1111 particular need to switch. --ben
|
|
1112 */
|
|
1113
|
|
1114 #if defined (I_SETSIG) && !defined (HPUX10) && !defined (LINUX)
|
428
|
1115 {
|
502
|
1116 int events = 0;
|
428
|
1117 ioctl (filedesc, I_GETSIG, &events);
|
|
1118 ioctl (filedesc, I_SETSIG, events | S_INPUT);
|
|
1119 }
|
502
|
1120 #elif defined (O_ASYNC)
|
|
1121 /* Generally FASYNC and O_ASYNC are both defined, and both equal;
|
|
1122 but let's not depend on that. O_ASYNC appears to be more
|
|
1123 standard (at least the Linux include files think so), so
|
|
1124 check it first. */
|
|
1125 fcntl (filedesc, F_SETFL, fcntl (filedesc, F_GETFL, 0) | O_ASYNC);
|
428
|
1126 #elif defined (FASYNC)
|
|
1127 fcntl (filedesc, F_SETFL, fcntl (filedesc, F_GETFL, 0) | FASYNC);
|
|
1128 #elif defined (FIOSSAIOSTAT)
|
|
1129 {
|
|
1130 /* DG: Changed for HP-UX. HP-UX uses different IOCTLs for
|
|
1131 sockets and other devices for some bizarre reason. We guess
|
|
1132 that an X device is a socket, and tty devices aren't. We then
|
|
1133 use the following crud to do the appropriate thing. */
|
|
1134 int on = 1;
|
|
1135 int ioctl_status; /* ####DG: check if IOCTL succeeds here. */
|
|
1136
|
|
1137 if (DEVICE_TTY_P (d))
|
|
1138 {
|
|
1139 ioctl_status = ioctl (filedesc, FIOSSAIOSTAT, &on);
|
|
1140 }
|
|
1141 #ifdef HAVE_WINDOW_SYSTEM
|
|
1142 else if (!DEVICE_STREAM_P (d))
|
|
1143 {
|
|
1144 ioctl_status = ioctl (filedesc, FIOASYNC, &on);
|
|
1145 }
|
|
1146 #endif
|
|
1147 }
|
|
1148 #elif defined (FIOASYNC)
|
|
1149 {
|
|
1150 int on = 1;
|
|
1151 ioctl (filedesc, FIOASYNC, &on);
|
|
1152 }
|
|
1153 #endif
|
|
1154
|
|
1155 #if defined (_CX_UX) /* #### Is this crap necessary? */
|
|
1156 EMACS_UNBLOCK_SIGNAL (SIGIO);
|
|
1157 #endif
|
|
1158 }
|
|
1159
|
|
1160 static void
|
|
1161 unrequest_sigio_on_device (struct device *d)
|
|
1162 {
|
|
1163 int filedesc = DEVICE_INFD (d);
|
|
1164
|
502
|
1165 #if defined (I_SETSIG) && !defined (HPUX10) && !defined (LINUX)
|
428
|
1166 {
|
502
|
1167 int events = 0;
|
428
|
1168 ioctl (filedesc, I_GETSIG, &events);
|
|
1169 ioctl (filedesc, I_SETSIG, events & ~S_INPUT);
|
|
1170 }
|
502
|
1171 #elif defined (O_ASYNC)
|
|
1172 fcntl (filedesc, F_SETFL, fcntl (filedesc, F_GETFL, 0) & ~O_ASYNC);
|
428
|
1173 #elif defined (FASYNC)
|
|
1174 fcntl (filedesc, F_SETFL, fcntl (filedesc, F_GETFL, 0) & ~FASYNC);
|
|
1175 #elif defined (FIOSSAIOSTAT)
|
|
1176 {
|
|
1177 /* DG: Changed for HP-UX. HP-UX uses different IOCTLs for
|
|
1178 sockets and other devices for some bizarre reason. We guess
|
|
1179 that an X device is a socket, and tty devices aren't. We then
|
|
1180 use the following crud to do the appropriate thing. */
|
|
1181
|
|
1182 int off = 0;
|
|
1183 int ioctl_status;
|
|
1184
|
|
1185 /* See comment for request_sigio_on_device */
|
|
1186
|
|
1187 if (DEVICE_TTY_P (d))
|
|
1188 {
|
|
1189 ioctl_status = ioctl (filedesc, FIOSSAIOSTAT, &off);
|
|
1190 }
|
|
1191 else
|
|
1192 {
|
|
1193 ioctl_status = ioctl (filedesc, FIOASYNC, &off);
|
|
1194 }
|
|
1195 }
|
|
1196 #elif defined (FIOASYNC)
|
|
1197 {
|
|
1198 int off = 0;
|
|
1199 ioctl (filedesc, FIOASYNC, &off);
|
|
1200 }
|
|
1201 #endif
|
|
1202 }
|
|
1203
|
|
1204 void
|
|
1205 request_sigio (void)
|
|
1206 {
|
|
1207 Lisp_Object devcons, concons;
|
|
1208
|
|
1209 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
1210 {
|
|
1211 struct device *d;
|
|
1212
|
|
1213 d = XDEVICE (XCAR (devcons));
|
|
1214
|
|
1215 if (!DEVICE_STREAM_P (d))
|
|
1216 request_sigio_on_device (d);
|
|
1217 }
|
|
1218 }
|
|
1219
|
|
1220 void
|
|
1221 unrequest_sigio (void)
|
|
1222 {
|
|
1223 Lisp_Object devcons, concons;
|
|
1224
|
|
1225 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
1226 {
|
|
1227 struct device *d;
|
|
1228
|
|
1229 d = XDEVICE (XCAR (devcons));
|
|
1230
|
|
1231 if (!DEVICE_STREAM_P (d))
|
|
1232 unrequest_sigio_on_device (d);
|
|
1233 }
|
|
1234 }
|
|
1235
|
|
1236 #endif /* SIGIO */
|
|
1237
|
|
1238 /* ------------------------------------------------------ */
|
|
1239 /* Changing Emacs's process group */
|
|
1240 /* ------------------------------------------------------ */
|
|
1241
|
|
1242 /* Saving and restoring the process group of Emacs's terminal. */
|
|
1243
|
|
1244 /* On some systems, apparently (?!) Emacs must be in its own process
|
|
1245 group in order to receive SIGIO correctly. On other systems
|
|
1246 (e.g. Solaris), it's not required and doing it makes things
|
|
1247 get fucked up. So, we only do it when
|
|
1248 SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP is defined. Basically,
|
|
1249 this is only required for BSD 4.2 systems. (Actually, I bet
|
|
1250 we don't have to do this at all -- those systems also
|
|
1251 required interrupt input, which we don't support.)
|
|
1252
|
|
1253 If Emacs was in its own process group (i.e. inherited_pgroup ==
|
|
1254 getpid ()), then we know we're running under a shell with job
|
|
1255 control (Emacs would never be run as part of a pipeline).
|
|
1256 Everything is fine.
|
|
1257
|
|
1258 If Emacs was not in its own process group, then we know we're
|
|
1259 running under a shell (or a caller) that doesn't know how to
|
|
1260 separate itself from Emacs (like sh). Emacs must be in its own
|
|
1261 process group in order to receive SIGIO correctly. In this
|
|
1262 situation, we put ourselves in our own pgroup, forcibly set the
|
|
1263 tty's pgroup to our pgroup, and make sure to restore and reinstate
|
|
1264 the tty's pgroup just like any other terminal setting. If
|
|
1265 inherited_group was not the tty's pgroup, then we'll get a
|
|
1266 SIGTTmumble when we try to change the tty's pgroup, and a CONT if
|
|
1267 it goes foreground in the future, which is what should happen. */
|
|
1268
|
|
1269 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1270
|
442
|
1271 static pid_t inherited_pgroup;
|
|
1272 static pid_t inherited_tty_pgroup;
|
428
|
1273
|
|
1274 #endif
|
|
1275
|
|
1276 void
|
|
1277 munge_tty_process_group (void)
|
|
1278 {
|
|
1279 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1280 if (noninteractive)
|
|
1281 return;
|
|
1282
|
|
1283 /* Only do this munging if we have a device on the controlling
|
|
1284 terminal. See the large comment below. */
|
|
1285
|
|
1286 if (CONSOLEP (Vcontrolling_terminal) &&
|
|
1287 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
|
|
1288 {
|
|
1289 int fd = open ("/dev/tty", O_RDWR, 0);
|
442
|
1290 pid_t me = getpid ();
|
428
|
1291 EMACS_BLOCK_SIGNAL (SIGTTOU);
|
|
1292 EMACS_SET_TTY_PROCESS_GROUP (fd, &me);
|
|
1293 EMACS_UNBLOCK_SIGNAL (SIGTTOU);
|
|
1294 close (fd);
|
|
1295 }
|
|
1296 #endif
|
|
1297 }
|
|
1298
|
|
1299 /* Split off the foreground process group to Emacs alone.
|
|
1300 When we are in the foreground, but not started in our own process
|
|
1301 group, redirect the TTY to point to our own process group. We need
|
|
1302 to be in our own process group to receive SIGIO properly. */
|
|
1303 static void
|
|
1304 munge_process_groups (void)
|
|
1305 {
|
|
1306 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1307 if (noninteractive)
|
|
1308 return;
|
|
1309
|
|
1310 EMACS_SEPARATE_PROCESS_GROUP ();
|
|
1311
|
|
1312 munge_tty_process_group ();
|
|
1313 #endif
|
|
1314 }
|
|
1315
|
|
1316 void
|
|
1317 unmunge_tty_process_group (void)
|
|
1318 {
|
|
1319 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1320 {
|
|
1321 int fd = open ("/dev/tty", O_RDWR, 0);
|
|
1322 EMACS_BLOCK_SIGNAL (SIGTTOU);
|
|
1323 EMACS_SET_TTY_PROCESS_GROUP (fd, &inherited_tty_pgroup);
|
|
1324 EMACS_UNBLOCK_SIGNAL (SIGTTOU);
|
|
1325 close (fd);
|
|
1326 }
|
|
1327 #endif
|
|
1328 }
|
|
1329
|
|
1330 /* Set the tty to our original foreground group.
|
|
1331 Also restore the original process group (put us back into sh's
|
|
1332 process group), so that ^Z will suspend both us and sh. */
|
|
1333 static void
|
|
1334 unmunge_process_groups (void)
|
|
1335 {
|
|
1336 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1337 if (noninteractive)
|
|
1338 return;
|
|
1339
|
|
1340 unmunge_tty_process_group ();
|
|
1341
|
|
1342 EMACS_SET_PROCESS_GROUP (inherited_pgroup);
|
|
1343 #endif
|
|
1344 }
|
|
1345
|
|
1346 /* According to some old wisdom, we need to be in a separate process
|
|
1347 group for SIGIO to work correctly (at least on some systems ...).
|
|
1348 So go ahead and put ourselves into our own process group. This
|
|
1349 will fail if we're already in our own process group, but who cares.
|
|
1350 Also record whether we were in our own process group. (In general,
|
|
1351 we will already be in our own process group if we were started from
|
|
1352 a job-control shell like csh, but not if we were started from sh).
|
|
1353
|
|
1354 If we succeeded in changing our process group, then we will no
|
|
1355 longer be in the foreground process group of our controlling
|
|
1356 terminal. Therefore, if we have a console open onto this terminal,
|
|
1357 we have to change the controlling terminal's foreground process
|
|
1358 group (otherwise we will get stopped with a SIGTTIN signal when
|
|
1359 attempting to read from the terminal). It's important,
|
|
1360 however, that we do this *only* when we have a console open onto
|
|
1361 the terminal. It's a decidedly bad idea to do so otherwise,
|
|
1362 especially if XEmacs was started from the background. */
|
|
1363
|
|
1364 void
|
|
1365 init_process_group (void)
|
|
1366 {
|
|
1367 #ifdef SIGIO_REQUIRES_SEPARATE_PROCESS_GROUP
|
|
1368 if (! noninteractive)
|
|
1369 {
|
|
1370 int fd = open ("/dev/tty", O_RDWR, 0);
|
|
1371 inherited_pgroup = EMACS_GET_PROCESS_GROUP ();
|
|
1372 EMACS_GET_TTY_PROCESS_GROUP (fd, &inherited_tty_pgroup);
|
|
1373 close (fd);
|
|
1374 EMACS_SEPARATE_PROCESS_GROUP ();
|
|
1375 }
|
|
1376 #endif
|
|
1377 }
|
|
1378
|
|
1379 void
|
|
1380 disconnect_controlling_terminal (void)
|
|
1381 {
|
|
1382 # ifdef HAVE_SETSID
|
|
1383 /* Controlling terminals are attached to a session.
|
|
1384 Create a new session for us; it will have no controlling
|
|
1385 terminal. This also, of course, puts us in our own
|
|
1386 process group. */
|
|
1387 setsid ();
|
|
1388 # else
|
|
1389 /* Put us in our own process group. */
|
|
1390 EMACS_SEPARATE_PROCESS_GROUP ();
|
|
1391 # if defined (TIOCNOTTY)
|
|
1392 /* This is the older way of disconnecting the controlling
|
|
1393 terminal, on 4.3 BSD. We must open /dev/tty; using
|
|
1394 filedesc 0 is not sufficient because it could be
|
|
1395 something else (e.g. our stdin was redirected to
|
|
1396 another terminal).
|
|
1397 */
|
|
1398 {
|
|
1399 int j = open ("/dev/tty", O_RDWR, 0);
|
|
1400 ioctl (j, TIOCNOTTY, 0);
|
|
1401 close (j);
|
|
1402 }
|
|
1403 # endif /* TIOCNOTTY */
|
|
1404 /*
|
|
1405 On systems without TIOCNOTTY and without
|
|
1406 setsid(), we don't need to do anything more to
|
|
1407 disconnect our controlling terminal. Here is
|
|
1408 what the man page for termio(7) from a SYSV 3.2
|
|
1409 system says:
|
|
1410
|
|
1411 "The first terminal file opened by the process group leader
|
|
1412 of a terminal file not already associated with a process
|
|
1413 group becomes the control terminal for that process group.
|
|
1414 The control terminal plays a special role in handling quit
|
|
1415 and interrupt signals, as discussed below. The control
|
|
1416 terminal is inherited by a child process during a fork(2).
|
|
1417 A process can break this association by changing its process
|
|
1418 group using setpgrp(2)."
|
|
1419
|
|
1420 */
|
|
1421 # endif /* not HAVE_SETSID */
|
|
1422 }
|
|
1423
|
|
1424
|
|
1425 /* ------------------------------------------------------ */
|
|
1426 /* Getting and setting emacs_tty structures */
|
|
1427 /* ------------------------------------------------------ */
|
|
1428
|
|
1429 /* It's wrong to encase these into #ifdef HAVE_TTY because we need
|
|
1430 them for child TTY processes. */
|
|
1431 /* However, this does break NT support while we don't do child TTY processes */
|
442
|
1432 #ifndef WIN32_NATIVE
|
428
|
1433
|
|
1434 /* Set *TC to the parameters associated with the terminal FD.
|
|
1435 Return zero if all's well, or -1 if we ran into an error we
|
|
1436 couldn't deal with. */
|
|
1437 int
|
|
1438 emacs_get_tty (int fd, struct emacs_tty *settings)
|
|
1439 {
|
|
1440 /* Retrieve the primary parameters - baud rate, character size, etcetera. */
|
|
1441 #ifdef HAVE_TCATTR
|
|
1442 /* We have those nifty POSIX tcmumbleattr functions. */
|
|
1443 if (tcgetattr (fd, &settings->main) < 0)
|
|
1444 return -1;
|
|
1445
|
|
1446 #elif defined HAVE_TERMIO
|
|
1447 /* The SYSV-style interface? */
|
|
1448 if (ioctl (fd, TCGETA, &settings->main) < 0)
|
|
1449 return -1;
|
|
1450
|
442
|
1451 #elif !defined (WIN32_NATIVE)
|
428
|
1452 /* I give up - I hope you have the BSD ioctls. */
|
|
1453 if (ioctl (fd, TIOCGETP, &settings->main) < 0)
|
|
1454 return -1;
|
|
1455 #endif /* HAVE_TCATTR */
|
|
1456
|
|
1457 /* Suivant - Do we have to get struct ltchars data? */
|
|
1458 #ifdef HAVE_LTCHARS
|
|
1459 if (ioctl (fd, TIOCGLTC, &settings->ltchars) < 0)
|
|
1460 return -1;
|
|
1461 #endif
|
|
1462
|
|
1463 /* How about a struct tchars and a wordful of lmode bits? */
|
|
1464 #ifdef HAVE_TCHARS
|
|
1465 if (ioctl (fd, TIOCGETC, &settings->tchars) < 0
|
|
1466 || ioctl (fd, TIOCLGET, &settings->lmode) < 0)
|
|
1467 return -1;
|
|
1468 #endif
|
|
1469
|
|
1470 /* We have survived the tempest. */
|
|
1471 return 0;
|
|
1472 }
|
|
1473
|
|
1474 /* Set the parameters of the tty on FD according to the contents of
|
|
1475 *SETTINGS. If FLUSHP is non-zero, we discard input.
|
430
|
1476 Return 0 if all went well, and -1 if anything failed.
|
|
1477 #### All current callers use FLUSHP == 0. */
|
428
|
1478
|
|
1479 int
|
|
1480 emacs_set_tty (int fd, struct emacs_tty *settings, int flushp)
|
|
1481 {
|
|
1482 /* Set the primary parameters - baud rate, character size, etcetera. */
|
|
1483 #ifdef HAVE_TCATTR
|
|
1484 int i;
|
|
1485 /* We have those nifty POSIX tcmumbleattr functions.
|
|
1486 William J. Smith <wjs@wiis.wang.com> writes:
|
|
1487 "POSIX 1003.1 defines tcsetattr() to return success if it was
|
|
1488 able to perform any of the requested actions, even if some
|
|
1489 of the requested actions could not be performed.
|
|
1490 We must read settings back to ensure tty setup properly.
|
|
1491 AIX requires this to keep tty from hanging occasionally." */
|
|
1492 /* This makes sure that we don't loop indefinitely in here. */
|
|
1493 for (i = 0 ; i < 10 ; i++)
|
|
1494 if (tcsetattr (fd, flushp ? TCSAFLUSH : TCSADRAIN, &settings->main) < 0)
|
|
1495 {
|
|
1496 if (errno == EINTR)
|
|
1497 continue;
|
|
1498 else
|
|
1499 return -1;
|
|
1500 }
|
|
1501 else
|
|
1502 {
|
|
1503 struct termios new;
|
|
1504
|
|
1505 /* Get the current settings, and see if they're what we asked for. */
|
|
1506 tcgetattr (fd, &new);
|
|
1507 /* We cannot use memcmp on the whole structure here because under
|
|
1508 * aix386 the termios structure has some reserved field that may
|
|
1509 * not be filled in.
|
|
1510 */
|
|
1511 if ( new.c_iflag == settings->main.c_iflag
|
|
1512 && new.c_oflag == settings->main.c_oflag
|
|
1513 && new.c_cflag == settings->main.c_cflag
|
|
1514 && new.c_lflag == settings->main.c_lflag
|
|
1515 && memcmp(new.c_cc, settings->main.c_cc, NCCS) == 0)
|
|
1516 break;
|
|
1517 else
|
|
1518 continue;
|
|
1519 }
|
|
1520 #elif defined HAVE_TERMIO
|
|
1521 /* The SYSV-style interface? */
|
|
1522 if (ioctl (fd, flushp ? TCSETAF : TCSETAW, &settings->main) < 0)
|
|
1523 return -1;
|
|
1524
|
442
|
1525 #elif !defined (WIN32_NATIVE)
|
428
|
1526 /* I give up - I hope you have the BSD ioctls. */
|
|
1527 if (ioctl (fd, (flushp) ? TIOCSETP : TIOCSETN, &settings->main) < 0)
|
|
1528 return -1;
|
|
1529 #endif /* HAVE_TCATTR */
|
|
1530
|
|
1531 /* Suivant - Do we have to get struct ltchars data? */
|
|
1532 #ifdef HAVE_LTCHARS
|
|
1533 if (ioctl (fd, TIOCSLTC, &settings->ltchars) < 0)
|
|
1534 return -1;
|
|
1535 #endif
|
|
1536
|
|
1537 /* How about a struct tchars and a wordful of lmode bits? */
|
|
1538 #ifdef HAVE_TCHARS
|
|
1539 if (ioctl (fd, TIOCSETC, &settings->tchars) < 0
|
|
1540 || ioctl (fd, TIOCLSET, &settings->lmode) < 0)
|
|
1541 return -1;
|
|
1542 #endif
|
|
1543
|
|
1544 /* We have survived the tempest. */
|
|
1545 return 0;
|
|
1546 }
|
|
1547
|
442
|
1548 #endif /* WIN32_NATIVE */
|
428
|
1549
|
|
1550 /* ------------------------------------------------------ */
|
|
1551 /* Initializing a device */
|
|
1552 /* ------------------------------------------------------ */
|
|
1553
|
|
1554 #ifdef HAVE_TTY
|
|
1555
|
|
1556 /* This may also be defined in stdio,
|
|
1557 but if so, this does no harm,
|
|
1558 and using the same name avoids wasting the other one's space. */
|
|
1559
|
|
1560 #if ((defined(USG) || defined(DGUX)) && !defined(__STDC__))
|
|
1561 char _sobuf[BUFSIZ+8];
|
|
1562 #elif (defined(USG) && !defined(LINUX) && !defined(_SCO_DS)) || defined(IRIX5)
|
|
1563 extern unsigned char _sobuf[BUFSIZ+8];
|
|
1564 #else
|
|
1565 char _sobuf[BUFSIZ];
|
|
1566 #endif
|
|
1567
|
|
1568 #if defined (TIOCGLTC) && defined (HAVE_LTCHARS) /* HAVE_LTCHARS */
|
|
1569 static struct ltchars new_ltchars = {-1,-1,-1,-1,-1,-1};
|
|
1570 #endif
|
|
1571 #ifdef TIOCGETC /* HAVE_TCHARS */
|
|
1572 #ifdef HAVE_TCHARS
|
|
1573 static struct tchars new_tchars = {-1,-1,-1,-1,-1,-1};
|
|
1574 #endif
|
|
1575 #endif
|
|
1576
|
|
1577 static void
|
|
1578 tty_init_sys_modes_on_device (struct device *d)
|
|
1579 {
|
|
1580 struct emacs_tty tty;
|
|
1581 int input_fd, output_fd;
|
|
1582 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
1583
|
|
1584 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
1585 output_fd = CONSOLE_TTY_DATA (con)->outfd;
|
|
1586
|
430
|
1587 emacs_get_tty (input_fd, &CONSOLE_TTY_DATA (con)->old_tty);
|
428
|
1588 tty = CONSOLE_TTY_DATA (con)->old_tty;
|
|
1589
|
|
1590 con->tty_erase_char = Qnil;
|
|
1591
|
|
1592 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
|
|
1593 /* after all those years... */
|
|
1594 con->tty_erase_char = make_char (tty.main.c_cc[VERASE]);
|
|
1595 #ifdef DGUX
|
|
1596 /* This allows meta to be sent on 8th bit. */
|
|
1597 tty.main.c_iflag &= ~INPCK; /* don't check input for parity */
|
|
1598 #endif
|
|
1599 tty.main.c_iflag |= (IGNBRK); /* Ignore break condition */
|
|
1600 tty.main.c_iflag &= ~ICRNL; /* Disable map of CR to NL on input */
|
|
1601 #ifdef ISTRIP
|
|
1602 tty.main.c_iflag &= ~ISTRIP; /* don't strip 8th bit on input */
|
|
1603 #endif
|
|
1604 tty.main.c_lflag &= ~ECHO; /* Disable echo */
|
|
1605 tty.main.c_lflag &= ~ICANON; /* Disable erase/kill processing */
|
|
1606 #ifdef IEXTEN
|
|
1607 tty.main.c_lflag &= ~IEXTEN; /* Disable other editing characters. */
|
|
1608 #endif
|
|
1609 tty.main.c_lflag |= ISIG; /* Enable signals */
|
|
1610 if (TTY_FLAGS (con).flow_control)
|
|
1611 {
|
|
1612 tty.main.c_iflag |= IXON; /* Enable start/stop output control */
|
|
1613 #ifdef IXANY
|
|
1614 tty.main.c_iflag &= ~IXANY;
|
|
1615 #endif /* IXANY */
|
|
1616 }
|
|
1617 else
|
|
1618 tty.main.c_iflag &= ~IXON; /* Disable start/stop output control */
|
|
1619 tty.main.c_oflag &= ~ONLCR; /* Disable map of NL to CR-NL
|
|
1620 on output */
|
513
|
1621
|
|
1622 #if 0
|
|
1623 /* We used to disable tab expansion here, but this is the user's decision. */
|
|
1624 #if defined (TABDLY) && defined (TAB3)
|
|
1625 if ((tty.main.c_oflag & TABDLY) == TAB3)
|
|
1626 tty.main.c_oflag &= ~TABDLY; /* Disable tab expansion (Posix). */
|
|
1627 #elif defined (OXTABS)
|
|
1628 tty.main.c_oflag &= ~OXTABS; /* Disable tab expansion (BSD). */
|
|
1629 #endif
|
|
1630 #endif /* 0 */
|
|
1631
|
428
|
1632 #ifdef CS8
|
|
1633 if (TTY_FLAGS (con).meta_key)
|
|
1634 {
|
|
1635 tty.main.c_cflag |= CS8; /* allow 8th bit on input */
|
|
1636 tty.main.c_cflag &= ~PARENB;/* Don't check parity */
|
|
1637 }
|
|
1638 #endif
|
|
1639 if (CONSOLE_TTY_DATA (con)->controlling_terminal)
|
|
1640 {
|
|
1641 tty.main.c_cc[VINTR] =
|
|
1642 CONSOLE_QUIT_CHAR (con); /* C-g (usually) gives SIGINT */
|
|
1643 /* Set up C-g for both SIGQUIT and SIGINT.
|
|
1644 We don't know which we will get, but we handle both alike
|
|
1645 so which one it really gives us does not matter. */
|
|
1646 tty.main.c_cc[VQUIT] = CONSOLE_QUIT_CHAR (con);
|
|
1647 }
|
|
1648 else
|
|
1649 {
|
|
1650 tty.main.c_cc[VINTR] = _POSIX_VDISABLE;
|
|
1651 tty.main.c_cc[VQUIT] = _POSIX_VDISABLE;
|
|
1652 }
|
|
1653 tty.main.c_cc[VMIN] = 1; /* Input should wait for at
|
|
1654 least 1 char */
|
|
1655 tty.main.c_cc[VTIME] = 0; /* no matter how long that takes. */
|
|
1656 #ifdef VSWTCH
|
|
1657 tty.main.c_cc[VSWTCH] = _POSIX_VDISABLE; /* Turn off shell layering use
|
|
1658 of C-z */
|
|
1659 #endif /* VSWTCH */
|
|
1660 /* There was some conditionalizing here on (mips or TCATTR), but
|
|
1661 I think that's wrong. There was one report of C-y (DSUSP) not being
|
|
1662 disabled on HP9000s700 systems, and this might fix it. */
|
|
1663 #ifdef VSUSP
|
|
1664 tty.main.c_cc[VSUSP] = _POSIX_VDISABLE; /* Turn off mips handling of C-z. */
|
|
1665 #endif /* VSUSP */
|
|
1666 #ifdef V_DSUSP
|
|
1667 tty.main.c_cc[V_DSUSP] = _POSIX_VDISABLE; /* Turn off mips handling of C-y. */
|
|
1668 #endif /* V_DSUSP */
|
|
1669 #ifdef VDSUSP /* Some systems have VDSUSP, some have V_DSUSP. */
|
|
1670 tty.main.c_cc[VDSUSP] = _POSIX_VDISABLE;
|
|
1671 #endif /* VDSUSP */
|
|
1672 #ifdef VLNEXT
|
|
1673 tty.main.c_cc[VLNEXT] = _POSIX_VDISABLE;
|
|
1674 #endif /* VLNEXT */
|
|
1675 #ifdef VREPRINT
|
|
1676 tty.main.c_cc[VREPRINT] = _POSIX_VDISABLE;
|
|
1677 #endif /* VREPRINT */
|
|
1678 #ifdef VWERASE
|
|
1679 tty.main.c_cc[VWERASE] = _POSIX_VDISABLE;
|
|
1680 #endif /* VWERASE */
|
|
1681 #ifdef VDISCARD
|
|
1682 tty.main.c_cc[VDISCARD] = _POSIX_VDISABLE;
|
|
1683 #endif /* VDISCARD */
|
|
1684 #ifdef VSTART
|
|
1685 tty.main.c_cc[VSTART] = _POSIX_VDISABLE;
|
|
1686 #endif /* VSTART */
|
|
1687 #ifdef VSTRT
|
|
1688 tty.main.c_cc[VSTRT] = _POSIX_VDISABLE; /* called VSTRT on some systems */
|
|
1689 #endif /* VSTART */
|
|
1690 #ifdef VSTOP
|
|
1691 tty.main.c_cc[VSTOP] = _POSIX_VDISABLE;
|
|
1692 #endif /* VSTOP */
|
|
1693 #ifdef SET_LINE_DISCIPLINE
|
|
1694 /* Need to explicitly request TERMIODISC line discipline or
|
|
1695 Ultrix's termios does not work correctly. */
|
|
1696 tty.main.c_line = SET_LINE_DISCIPLINE;
|
|
1697 #endif
|
|
1698
|
|
1699 #ifdef AIX
|
|
1700 #ifndef IBMR2AIX
|
|
1701 /* AIX enhanced edit loses NULs, so disable it. */
|
|
1702 tty.main.c_line = 0;
|
|
1703 tty.main.c_iflag &= ~ASCEDIT;
|
|
1704 #else
|
|
1705 tty.main.c_cc[VSTRT] = 255;
|
|
1706 tty.main.c_cc[VSTOP] = 255;
|
|
1707 tty.main.c_cc[VSUSP] = 255;
|
|
1708 tty.main.c_cc[VDSUSP] = 255;
|
|
1709 #endif /* IBMR2AIX */
|
|
1710 /* Also, PTY overloads NUL and BREAK.
|
|
1711 don't ignore break, but don't signal either, so it looks like NUL.
|
|
1712 This really serves a purpose only if running in an XTERM window
|
|
1713 or via TELNET or the like, but does no harm elsewhere. */
|
|
1714 tty.main.c_iflag &= ~IGNBRK;
|
|
1715 tty.main.c_iflag &= ~BRKINT;
|
|
1716 #endif /* AIX */
|
|
1717 #else /* if not HAVE_TERMIO */
|
442
|
1718 #if !defined (WIN32_NATIVE)
|
428
|
1719 con->tty_erase_char = make_char (tty.main.sg_erase);
|
|
1720 tty.main.sg_flags &= ~(ECHO | CRMOD | XTABS);
|
|
1721 if (TTY_FLAGS (con).meta_key)
|
|
1722 tty.main.sg_flags |= ANYP;
|
|
1723 /* #### should we be using RAW mode here? */
|
|
1724 tty.main.sg_flags |= /* interrupt_input ? RAW : */ CBREAK;
|
442
|
1725 #endif /* not WIN32_NATIVE */
|
428
|
1726 #endif /* not HAVE_TERMIO */
|
|
1727
|
|
1728 /* If going to use CBREAK mode, we must request C-g to interrupt
|
|
1729 and turn off start and stop chars, etc. If not going to use
|
|
1730 CBREAK mode, do this anyway so as to turn off local flow
|
|
1731 control for user coming over network on 4.2; in this case,
|
|
1732 only t_stopc and t_startc really matter. */
|
|
1733 #ifndef HAVE_TERMIO
|
|
1734 #ifdef HAVE_TCHARS
|
|
1735 /* Note: if not using CBREAK mode, it makes no difference how we
|
|
1736 set this */
|
|
1737 tty.tchars = new_tchars;
|
|
1738 tty.tchars.t_intrc = CONSOLE_QUIT_CHAR (con);
|
|
1739 if (TTY_FLAGS (con).flow_control)
|
|
1740 {
|
|
1741 tty.tchars.t_startc = '\021';
|
|
1742 tty.tchars.t_stopc = '\023';
|
|
1743 }
|
|
1744
|
|
1745 tty.lmode = LDECCTQ | LLITOUT | LPASS8 | LNOFLSH |
|
|
1746 CONSOLE_TTY_DATA (con)->old_tty.lmode;
|
|
1747
|
|
1748 #if defined (ultrix) || defined (__bsdi__)
|
|
1749 /* Under Ultrix 4.2a, leaving this out doesn't seem to hurt
|
|
1750 anything, and leaving it in breaks the meta key. Go figure. */
|
|
1751 /* Turning off ONLCR is enough under BSD/386. Leave the general
|
|
1752 output post-processing flag alone since for some reason it
|
|
1753 doesn't get reset after XEmacs goes away. */
|
|
1754 tty.lmode &= ~LLITOUT;
|
|
1755 #endif
|
|
1756
|
|
1757 #endif /* HAVE_TCHARS */
|
|
1758 #endif /* not HAVE_TERMIO */
|
|
1759
|
|
1760 #ifdef HAVE_LTCHARS
|
|
1761 tty.ltchars = new_ltchars;
|
|
1762 #endif /* HAVE_LTCHARS */
|
|
1763
|
430
|
1764 emacs_set_tty (input_fd, &tty, 0);
|
428
|
1765
|
|
1766 /* This code added to insure that, if flow-control is not to be used,
|
|
1767 we have an unlocked terminal at the start. */
|
|
1768
|
|
1769 #ifdef TCXONC
|
|
1770 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TCXONC, 1);
|
|
1771 #endif
|
|
1772 #ifdef TIOCSTART
|
|
1773 if (!TTY_FLAGS (con).flow_control) ioctl (input_fd, TIOCSTART, 0);
|
|
1774 #endif
|
|
1775
|
|
1776 #if defined (HAVE_TERMIOS) || defined (HPUX9)
|
|
1777 #ifdef TCOON
|
|
1778 if (!TTY_FLAGS (con).flow_control) tcflow (input_fd, TCOON);
|
|
1779 #endif
|
|
1780 #endif
|
|
1781 #ifdef AIXHFT
|
|
1782 hft_init (con);
|
|
1783 #ifdef IBMR2AIX
|
|
1784 {
|
|
1785 /* IBM's HFT device usually thinks a ^J should be LF/CR.
|
|
1786 We need it to be only LF. This is the way that is
|
|
1787 done. */
|
|
1788 struct termio tty;
|
|
1789
|
|
1790 if (ioctl (output_fd, HFTGETID, &tty) != -1)
|
|
1791 write (output_fd, "\033[20l", 5);
|
|
1792 }
|
|
1793 #endif
|
|
1794 #endif
|
|
1795
|
|
1796 #if 0 /* We do our own buffering with lstreams. */
|
|
1797 #ifdef _IOFBF
|
|
1798 /* This symbol is defined on recent USG systems.
|
|
1799 Someone says without this call USG won't really buffer the file
|
|
1800 even with a call to setbuf. */
|
|
1801 setvbuf (CONSOLE_TTY_DATA (con)->outfd, (char *) _sobuf, _IOFBF, sizeof _sobuf);
|
|
1802 #else
|
|
1803 setbuf (CONSOLE_TTY_DATA (con)->outfd, (char *) _sobuf);
|
|
1804 #endif
|
|
1805 #endif
|
|
1806 set_tty_modes (con);
|
|
1807 }
|
|
1808
|
|
1809 #endif /* HAVE_TTY */
|
|
1810
|
|
1811 void
|
|
1812 init_one_device (struct device *d)
|
|
1813 {
|
|
1814 #ifdef HAVE_TTY
|
|
1815 if (DEVICE_TTY_P (d))
|
|
1816 tty_init_sys_modes_on_device (d);
|
|
1817 #endif
|
|
1818 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
|
|
1819 if (!DEVICE_STREAM_P (d))
|
|
1820 {
|
|
1821 init_sigio_on_device (d);
|
|
1822 request_sigio_on_device (d);
|
|
1823 }
|
|
1824 #endif
|
|
1825 }
|
|
1826
|
|
1827 void
|
|
1828 init_one_console (struct console *con)
|
|
1829 {
|
|
1830 Lisp_Object devcons;
|
|
1831
|
|
1832 CONSOLE_DEVICE_LOOP (devcons, con)
|
|
1833 {
|
|
1834 struct device *d = XDEVICE (XCAR (devcons));
|
|
1835
|
|
1836 init_one_device (d);
|
|
1837 }
|
|
1838 }
|
|
1839
|
|
1840 void
|
|
1841 reinit_initial_console (void)
|
|
1842 {
|
|
1843 munge_process_groups ();
|
|
1844 if (CONSOLEP (Vcontrolling_terminal) &&
|
|
1845 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
|
|
1846 init_one_console (XCONSOLE (Vcontrolling_terminal));
|
|
1847 }
|
|
1848
|
|
1849
|
|
1850 /* ------------------------------------------------------ */
|
|
1851 /* Other TTY functions */
|
|
1852 /* ------------------------------------------------------ */
|
|
1853
|
|
1854 #ifdef HAVE_TTY
|
|
1855
|
|
1856 #if 0 /* not currently used */
|
|
1857
|
|
1858 /* Return nonzero if safe to use tabs in output.
|
|
1859 At the time this is called, init_sys_modes has not been done yet. */
|
|
1860
|
|
1861 int
|
|
1862 tabs_safe_p (struct device *d)
|
|
1863 {
|
|
1864 #ifdef HAVE_TTY
|
|
1865 if (DEVICE_TTY_P (d))
|
|
1866 {
|
|
1867 struct emacs_tty tty;
|
|
1868
|
430
|
1869 emacs_get_tty (DEVICE_INFD (d), &tty);
|
428
|
1870 return EMACS_TTY_TABS_OK (&tty);
|
|
1871 }
|
|
1872 #endif
|
|
1873 return 1;
|
|
1874 }
|
|
1875
|
|
1876 #endif /* 0 */
|
|
1877
|
|
1878 /* Get terminal size from system.
|
|
1879 Store number of lines into *heightp and width into *widthp.
|
|
1880 If zero or a negative number is stored, the value is not valid. */
|
|
1881
|
|
1882 void
|
|
1883 get_tty_device_size (struct device *d, int *widthp, int *heightp)
|
|
1884 {
|
|
1885 int input_fd = DEVICE_INFD (d);
|
|
1886
|
|
1887 assert (DEVICE_TTY_P (d));
|
|
1888
|
|
1889 #ifdef TIOCGWINSZ
|
|
1890 {
|
|
1891 /* BSD-style. */
|
|
1892 struct winsize size;
|
|
1893
|
|
1894 if (ioctl (input_fd, TIOCGWINSZ, &size) == -1)
|
|
1895 *widthp = *heightp = 0;
|
|
1896 else
|
|
1897 {
|
|
1898 *widthp = size.ws_col;
|
|
1899 *heightp = size.ws_row;
|
|
1900 }
|
|
1901 }
|
|
1902 #elif defined TIOCGSIZE
|
|
1903 {
|
|
1904 /* SunOS - style. */
|
|
1905 struct ttysize size;
|
|
1906
|
|
1907 if (ioctl (input_fd, TIOCGSIZE, &size) == -1)
|
|
1908 *widthp = *heightp = 0;
|
|
1909 else
|
|
1910 {
|
|
1911 *widthp = size.ts_cols;
|
|
1912 *heightp = size.ts_lines;
|
|
1913 }
|
|
1914 }
|
|
1915 #else /* system doesn't know size */
|
|
1916
|
|
1917 *widthp = 0;
|
|
1918 *heightp = 0;
|
|
1919
|
|
1920 #endif /* not !TIOCGWINSZ */
|
|
1921 }
|
|
1922
|
|
1923 #endif /* HAVE_TTY */
|
|
1924
|
|
1925
|
|
1926 /* ------------------------------------------------------ */
|
|
1927 /* Is device 8 bit ? */
|
|
1928 /* ------------------------------------------------------ */
|
|
1929
|
|
1930 #ifdef HAVE_TTY
|
|
1931
|
|
1932 int
|
|
1933 eight_bit_tty (struct device *d)
|
|
1934 {
|
|
1935 struct emacs_tty s;
|
|
1936 int input_fd;
|
|
1937 int eight_bit = 0;
|
|
1938
|
|
1939 assert (DEVICE_TTY_P (d));
|
|
1940 input_fd = DEVICE_INFD (d);
|
|
1941
|
430
|
1942 emacs_get_tty (input_fd, &s);
|
428
|
1943
|
|
1944 #if defined (HAVE_TERMIO) || defined (HAVE_TERMIOS)
|
|
1945 eight_bit = (s.main.c_cflag & CSIZE) == CS8;
|
|
1946 #else
|
|
1947 eight_bit = 0; /* I don't know how to do it */
|
|
1948 #endif
|
|
1949 return eight_bit;
|
|
1950 }
|
|
1951
|
|
1952 #endif /* HAVE_TTY */
|
|
1953
|
|
1954
|
|
1955 /* ------------------------------------------------------ */
|
|
1956 /* Resetting a device */
|
|
1957 /* ------------------------------------------------------ */
|
|
1958
|
|
1959 #ifdef HAVE_TTY
|
|
1960
|
|
1961 /* Prepare the terminal for exiting Emacs; move the cursor to the
|
|
1962 bottom of the frame, turn off interrupt-driven I/O, etc. */
|
|
1963 static void
|
|
1964 tty_reset_sys_modes_on_device (struct device *d)
|
|
1965 {
|
|
1966 int input_fd, output_fd;
|
|
1967 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
1968
|
|
1969 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
1970 output_fd = CONSOLE_TTY_DATA (con)->outfd;
|
|
1971
|
|
1972 #if defined (IBMR2AIX) && defined (AIXHFT)
|
|
1973 {
|
|
1974 /* HFT consoles normally use ^J as a LF/CR. We forced it to
|
|
1975 do the LF only. Now, we need to reset it. */
|
|
1976 struct termio tty;
|
|
1977
|
|
1978 if (ioctl (output_fd, HFTGETID, &tty) != -1)
|
|
1979 write (output_fd, "\033[20h", 5);
|
|
1980 }
|
|
1981 #endif
|
|
1982
|
|
1983 tty_redisplay_shutdown (con);
|
|
1984 /* reset_tty_modes() flushes the connection at its end. */
|
|
1985 reset_tty_modes (con);
|
|
1986
|
|
1987 #if defined (BSD)
|
|
1988 /* Avoid possible loss of output when changing terminal modes. */
|
|
1989 fsync (output_fd);
|
|
1990 #endif
|
|
1991
|
430
|
1992 while (emacs_set_tty (input_fd, &CONSOLE_TTY_DATA (con)->old_tty, 0)
|
428
|
1993 < 0 && errno == EINTR)
|
|
1994 ;
|
|
1995
|
|
1996 #ifdef SET_LINE_DISCIPLINE
|
|
1997 /* Ultrix's termios *ignores* any line discipline except TERMIODISC.
|
|
1998 A different old line discipline is therefore not restored, yet.
|
|
1999 Restore the old line discipline by hand. */
|
|
2000 ioctl (input_fd, TIOCSETD, &old_tty.main.c_line);
|
|
2001 #endif
|
|
2002
|
|
2003 #ifdef AIXHFT
|
|
2004 hft_reset (con);
|
|
2005 #endif
|
|
2006
|
|
2007 }
|
|
2008
|
|
2009 #endif /* HAVE_TTY */
|
|
2010
|
|
2011 void
|
|
2012 reset_one_device (struct device *d)
|
|
2013 {
|
|
2014 #ifdef HAVE_TTY
|
|
2015 if (DEVICE_TTY_P (d))
|
|
2016 tty_reset_sys_modes_on_device (d);
|
|
2017 else
|
|
2018 #endif
|
|
2019 if (DEVICE_STREAM_P (d))
|
|
2020 fflush (CONSOLE_STREAM_DATA (XCONSOLE (DEVICE_CONSOLE (d)))->out);
|
|
2021 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
|
|
2022 if (!DEVICE_STREAM_P (d))
|
|
2023 {
|
|
2024 unrequest_sigio_on_device (d);
|
|
2025 reset_sigio_on_device (d);
|
|
2026 }
|
|
2027 #endif
|
|
2028 }
|
|
2029
|
|
2030 void
|
|
2031 reset_one_console (struct console *con)
|
|
2032 {
|
|
2033 /* Note: this can be called during GC. */
|
|
2034 Lisp_Object devcons;
|
|
2035
|
|
2036 CONSOLE_DEVICE_LOOP (devcons, con)
|
|
2037 {
|
|
2038 struct device *d = XDEVICE (XCAR (devcons));
|
|
2039
|
|
2040 reset_one_device (d);
|
|
2041 }
|
|
2042 }
|
|
2043
|
|
2044 void
|
|
2045 reset_all_consoles (void)
|
|
2046 {
|
|
2047 /* Note: this can be called during GC. */
|
|
2048 Lisp_Object concons;
|
|
2049
|
|
2050 CONSOLE_LOOP (concons)
|
|
2051 {
|
|
2052 struct console *con = XCONSOLE (XCAR (concons));
|
|
2053
|
|
2054 reset_one_console (con);
|
|
2055 }
|
|
2056
|
|
2057 unmunge_process_groups ();
|
|
2058 }
|
|
2059
|
|
2060 void
|
|
2061 reset_initial_console (void)
|
|
2062 {
|
|
2063 if (CONSOLEP (Vcontrolling_terminal) &&
|
|
2064 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)))
|
|
2065 reset_one_console (XCONSOLE (Vcontrolling_terminal));
|
|
2066 unmunge_process_groups ();
|
|
2067 }
|
|
2068
|
|
2069
|
|
2070 /* ------------------------------------------------------ */
|
|
2071 /* extra TTY stuff under AIX */
|
|
2072 /* ------------------------------------------------------ */
|
|
2073
|
|
2074 #ifdef AIXHFT
|
|
2075
|
|
2076 /* Called from init_sys_modes. */
|
|
2077 static void
|
|
2078 hft_init (struct console *con)
|
|
2079 {
|
|
2080 int junk;
|
|
2081 int input_fd;
|
|
2082
|
|
2083 assert (CONSOLE_TTY_P (con));
|
|
2084 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
2085
|
|
2086 /* If we're not on an HFT we shouldn't do any of this. We determine
|
|
2087 if we are on an HFT by trying to get an HFT error code. If this
|
|
2088 call fails, we're not on an HFT. */
|
|
2089 #ifdef IBMR2AIX
|
|
2090 if (ioctl (input_fd, HFQERROR, &junk) < 0)
|
|
2091 return;
|
|
2092 #else /* not IBMR2AIX */
|
|
2093 if (ioctl (input_fd, HFQEIO, 0) < 0)
|
|
2094 return;
|
|
2095 #endif /* not IBMR2AIX */
|
|
2096
|
|
2097 /* On AIX the default hft keyboard mapping uses backspace rather than delete
|
|
2098 as the rubout key's ASCII code. Here this is changed. The bug is that
|
|
2099 there's no way to determine the old mapping, so in reset_one_console
|
|
2100 we need to assume that the normal map had been present. Of course, this
|
|
2101 code also doesn't help if on a terminal emulator which doesn't understand
|
|
2102 HFT VTD's. */
|
|
2103 {
|
|
2104 struct hfbuf buf;
|
|
2105 struct hfkeymap keymap;
|
|
2106
|
|
2107 buf.hf_bufp = (char *)&keymap;
|
|
2108 buf.hf_buflen = sizeof (keymap);
|
|
2109 keymap.hf_nkeys = 2;
|
|
2110 keymap.hfkey[0].hf_kpos = 15;
|
|
2111 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE;
|
|
2112 #ifdef IBMR2AIX
|
|
2113 keymap.hfkey[0].hf_keyidh = '<';
|
|
2114 #else /* not IBMR2AIX */
|
|
2115 keymap.hfkey[0].hf_page = '<';
|
|
2116 #endif /* not IBMR2AIX */
|
|
2117 keymap.hfkey[0].hf_char = 127;
|
|
2118 keymap.hfkey[1].hf_kpos = 15;
|
|
2119 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT;
|
|
2120 #ifdef IBMR2AIX
|
|
2121 keymap.hfkey[1].hf_keyidh = '<';
|
|
2122 #else /* not IBMR2AIX */
|
|
2123 keymap.hfkey[1].hf_page = '<';
|
|
2124 #endif /* not IBMR2AIX */
|
|
2125 keymap.hfkey[1].hf_char = 127;
|
|
2126 hftctl (input_fd, HFSKBD, &buf);
|
|
2127 }
|
|
2128 /* #### Should probably set a console TTY flag here. */
|
|
2129 #if 0
|
|
2130 /* The HFT system on AIX doesn't optimize for scrolling, so it's really ugly
|
|
2131 at times. */
|
|
2132 line_ins_del_ok = char_ins_del_ok = 0;
|
|
2133 #endif /* 0 */
|
|
2134 }
|
|
2135
|
|
2136 /* Reset the rubout key to backspace. */
|
|
2137
|
|
2138 static void
|
|
2139 hft_reset (struct console *con)
|
|
2140 {
|
|
2141 struct hfbuf buf;
|
|
2142 struct hfkeymap keymap;
|
|
2143 int junk;
|
|
2144 int input_fd;
|
|
2145
|
|
2146 assert (CONSOLE_TTY_P (con));
|
|
2147 input_fd = CONSOLE_TTY_DATA (con)->infd;
|
|
2148
|
|
2149 #ifdef IBMR2AIX
|
|
2150 if (ioctl (input_fd, HFQERROR, &junk) < 0)
|
|
2151 return;
|
|
2152 #else /* not IBMR2AIX */
|
|
2153 if (ioctl (input_fd, HFQEIO, 0) < 0)
|
|
2154 return;
|
|
2155 #endif /* not IBMR2AIX */
|
|
2156
|
|
2157 buf.hf_bufp = (char *)&keymap;
|
|
2158 buf.hf_buflen = sizeof (keymap);
|
|
2159 keymap.hf_nkeys = 2;
|
|
2160 keymap.hfkey[0].hf_kpos = 15;
|
|
2161 keymap.hfkey[0].hf_kstate = HFMAPCHAR | HFSHFNONE;
|
|
2162 #ifdef IBMR2AIX
|
|
2163 keymap.hfkey[0].hf_keyidh = '<';
|
|
2164 #else /* not IBMR2AIX */
|
|
2165 keymap.hfkey[0].hf_page = '<';
|
|
2166 #endif /* not IBMR2AIX */
|
|
2167 keymap.hfkey[0].hf_char = 8;
|
|
2168 keymap.hfkey[1].hf_kpos = 15;
|
|
2169 keymap.hfkey[1].hf_kstate = HFMAPCHAR | HFSHFSHFT;
|
|
2170 #ifdef IBMR2AIX
|
|
2171 keymap.hfkey[1].hf_keyidh = '<';
|
|
2172 #else /* not IBMR2AIX */
|
|
2173 keymap.hfkey[1].hf_page = '<';
|
|
2174 #endif /* not IBMR2AIX */
|
|
2175 keymap.hfkey[1].hf_char = 8;
|
|
2176 hftctl (input_fd, HFSKBD, &buf);
|
|
2177 }
|
|
2178
|
|
2179 #endif /* AIXHFT */
|
|
2180
|
|
2181
|
|
2182 /************************************************************************/
|
|
2183 /* limits of text/data segments */
|
|
2184 /************************************************************************/
|
|
2185
|
440
|
2186 #if !defined(CANNOT_DUMP) && !defined(PDUMP)
|
428
|
2187 #define NEED_STARTS
|
|
2188 #endif
|
|
2189
|
|
2190 #ifndef SYSTEM_MALLOC
|
|
2191 #ifndef NEED_STARTS
|
|
2192 #define NEED_STARTS
|
|
2193 #endif
|
|
2194 #endif
|
|
2195
|
|
2196 #ifdef NEED_STARTS
|
|
2197 /* Some systems that cannot dump also cannot implement these. */
|
|
2198
|
|
2199 /*
|
|
2200 * Return the address of the start of the text segment prior to
|
|
2201 * doing an unexec. After unexec the return value is undefined.
|
|
2202 * See crt0.c for further explanation and _start.
|
|
2203 *
|
|
2204 */
|
|
2205
|
440
|
2206 #if !defined(HAVE_TEXT_START) && !defined(PDUMP)
|
|
2207
|
442
|
2208 EXTERN_C int _start (void);
|
428
|
2209
|
|
2210 char *
|
|
2211 start_of_text (void)
|
|
2212 {
|
|
2213 #ifdef TEXT_START
|
442
|
2214 return (char *) TEXT_START;
|
428
|
2215 #else
|
442
|
2216 return (char *) _start;
|
428
|
2217 #endif /* TEXT_START */
|
|
2218 }
|
440
|
2219 #endif /* !defined(HAVE_TEXT_START) && !defined(PDUMP) */
|
428
|
2220
|
|
2221 /*
|
|
2222 * Return the address of the start of the data segment prior to
|
|
2223 * doing an unexec. After unexec the return value is undefined.
|
442
|
2224 * See ecrt0.c for further information and definition of data_start.
|
428
|
2225 *
|
|
2226 * Apparently, on BSD systems this is etext at startup. On
|
|
2227 * USG systems (swapping) this is highly mmu dependent and
|
|
2228 * is also dependent on whether or not the program is running
|
|
2229 * with shared text. Generally there is a (possibly large)
|
|
2230 * gap between end of text and start of data with shared text.
|
|
2231 *
|
|
2232 * On Uniplus+ systems with shared text, data starts at a
|
|
2233 * fixed address. Each port (from a given oem) is generally
|
|
2234 * different, and the specific value of the start of data can
|
|
2235 * be obtained via the UniPlus+ specific "uvar" system call,
|
|
2236 * however the method outlined in crt0.c seems to be more portable.
|
|
2237 *
|
|
2238 * Probably what will have to happen when a USG unexec is available,
|
|
2239 * at least on UniPlus, is temacs will have to be made unshared so
|
|
2240 * that text and data are contiguous. Then once loadup is complete,
|
|
2241 * unexec will produce a shared executable where the data can be
|
|
2242 * at the normal shared text boundary and the startofdata variable
|
|
2243 * will be patched by unexec to the correct value.
|
|
2244 *
|
|
2245 */
|
|
2246
|
442
|
2247 #if defined(ORDINARY_LINK) && !defined(MINGW)
|
428
|
2248 extern char **environ;
|
|
2249 #endif
|
|
2250
|
|
2251 void *
|
|
2252 start_of_data (void)
|
|
2253 {
|
|
2254 #ifdef DATA_START
|
|
2255 return ((char *) DATA_START);
|
|
2256 #else
|
452
|
2257 #if defined (ORDINARY_LINK) || defined(PDUMP)
|
428
|
2258 /*
|
|
2259 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
|
|
2260 * data_start isn't defined. We take the address of environ, which
|
|
2261 * is known to live at or near the start of the system crt0.c, and
|
|
2262 * we don't sweat the handful of bytes that might lose.
|
|
2263 */
|
442
|
2264 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
|
428
|
2265 extern char* static_heap_base;
|
|
2266 if (!initialized)
|
|
2267 return static_heap_base;
|
|
2268 #endif
|
|
2269 return((char *) &environ);
|
|
2270 #else
|
|
2271 extern int data_start;
|
|
2272 return ((char *) &data_start);
|
|
2273 #endif /* ORDINARY_LINK */
|
|
2274 #endif /* DATA_START */
|
|
2275 }
|
|
2276 #endif /* NEED_STARTS (not CANNOT_DUMP or not SYSTEM_MALLOC) */
|
|
2277
|
440
|
2278 #if !defined(CANNOT_DUMP) && !defined(PDUMP)
|
428
|
2279 /* Some systems that cannot dump also cannot implement these. */
|
|
2280
|
|
2281 /*
|
|
2282 * Return the address of the end of the text segment prior to
|
|
2283 * doing an unexec. After unexec the return value is undefined.
|
|
2284 */
|
|
2285
|
|
2286 char *
|
|
2287 end_of_text (void)
|
|
2288 {
|
|
2289 #ifdef TEXT_END
|
|
2290 return ((char *) TEXT_END);
|
|
2291 #else
|
|
2292 extern int etext;
|
|
2293 return ((char *) &etext);
|
|
2294 #endif
|
|
2295 }
|
|
2296
|
|
2297 /*
|
|
2298 * Return the address of the end of the data segment prior to
|
|
2299 * doing an unexec. After unexec the return value is undefined.
|
|
2300 */
|
|
2301
|
|
2302 char *
|
|
2303 end_of_data (void)
|
|
2304 {
|
|
2305 #ifdef DATA_END
|
|
2306 return ((char *) DATA_END);
|
|
2307 #else
|
|
2308 extern int edata;
|
|
2309 return ((char *) &edata);
|
|
2310 #endif
|
|
2311 }
|
|
2312
|
440
|
2313 #endif /* !defined(CANNOT_DUMP) && !defined(PDUMP) */
|
428
|
2314
|
|
2315
|
|
2316 /************************************************************************/
|
|
2317 /* get the system name */
|
|
2318 /************************************************************************/
|
|
2319
|
|
2320 /* init_system_name sets up the string for the Lisp function
|
|
2321 system-name to return. */
|
|
2322
|
|
2323 extern Lisp_Object Vsystem_name;
|
|
2324
|
|
2325 void
|
|
2326 init_system_name (void)
|
|
2327 {
|
442
|
2328 #if defined (WIN32_NATIVE)
|
428
|
2329 char hostname [MAX_COMPUTERNAME_LENGTH + 1];
|
440
|
2330 size_t size = sizeof (hostname);
|
428
|
2331 GetComputerName (hostname, &size);
|
|
2332 Vsystem_name = build_string (hostname);
|
|
2333 #elif !defined (HAVE_GETHOSTNAME)
|
|
2334 struct utsname uts;
|
|
2335 uname (&uts);
|
|
2336 Vsystem_name = build_string (uts.nodename);
|
|
2337 #else /* HAVE_GETHOSTNAME */
|
|
2338 unsigned int hostname_size = 256;
|
|
2339 char *hostname = (char *) alloca (hostname_size);
|
|
2340
|
|
2341 /* Try to get the host name; if the buffer is too short, try
|
|
2342 again. Apparently, the only indication gethostname gives of
|
|
2343 whether the buffer was large enough is the presence or absence
|
|
2344 of a '\0' in the string. Eech. */
|
|
2345 for (;;)
|
|
2346 {
|
|
2347 gethostname (hostname, hostname_size - 1);
|
|
2348 hostname[hostname_size - 1] = '\0';
|
|
2349
|
|
2350 /* Was the buffer large enough for the '\0'? */
|
|
2351 if (strlen (hostname) < (size_t) (hostname_size - 1))
|
|
2352 break;
|
|
2353
|
|
2354 hostname_size <<= 1;
|
|
2355 hostname = (char *) alloca (hostname_size);
|
|
2356 }
|
|
2357 # if defined( HAVE_SOCKETS) && !defined(BROKEN_CYGWIN)
|
|
2358 /* Turn the hostname into the official, fully-qualified hostname.
|
|
2359 Don't do this if we're going to dump; this can confuse system
|
|
2360 libraries on some machines and make the dumped emacs core dump. */
|
|
2361 # ifndef CANNOT_DUMP
|
|
2362 if (initialized)
|
|
2363 # endif /* not CANNOT_DUMP */
|
|
2364 if (!strchr (hostname, '.'))
|
|
2365 {
|
440
|
2366 # if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETNAMEINFO))
|
428
|
2367 struct hostent *hp = NULL;
|
|
2368 int count;
|
440
|
2369 # ifdef TRY_AGAIN
|
428
|
2370 for (count = 0; count < 10; count++)
|
|
2371 {
|
|
2372 h_errno = 0;
|
440
|
2373 # endif
|
428
|
2374 /* Some systems can't handle SIGALARM/SIGIO in gethostbyname(). */
|
|
2375 stop_interrupts ();
|
|
2376 hp = gethostbyname (hostname);
|
|
2377 start_interrupts ();
|
440
|
2378 # ifdef TRY_AGAIN
|
428
|
2379 if (! (hp == 0 && h_errno == TRY_AGAIN))
|
|
2380 break;
|
|
2381 Fsleep_for (make_int (1));
|
|
2382 }
|
440
|
2383 # endif
|
428
|
2384 if (hp)
|
|
2385 {
|
442
|
2386 const char *fqdn = (const char *) hp->h_name;
|
428
|
2387
|
|
2388 if (!strchr (fqdn, '.'))
|
|
2389 {
|
|
2390 /* We still don't have a fully qualified domain name.
|
|
2391 Try to find one in the list of alternate names */
|
|
2392 char **alias = hp->h_aliases;
|
|
2393 while (*alias && !strchr (*alias, '.'))
|
|
2394 alias++;
|
|
2395 if (*alias)
|
|
2396 fqdn = *alias;
|
|
2397 }
|
|
2398 hostname = (char *) alloca (strlen (fqdn) + 1);
|
|
2399 strcpy (hostname, fqdn);
|
|
2400 }
|
440
|
2401 # else /* !(HAVE_GETADDRINFO && HAVE_GETNAMEINFO) */
|
|
2402 struct addrinfo hints, *res;
|
|
2403
|
|
2404 xzero (hints);
|
|
2405 hints.ai_flags = AI_CANONNAME;
|
|
2406 hints.ai_family = AF_UNSPEC;
|
|
2407 hints.ai_socktype = SOCK_STREAM;
|
|
2408 hints.ai_protocol = 0;
|
|
2409 if (!getaddrinfo (hostname, NULL, &hints, &res))
|
|
2410 {
|
|
2411 hostname = (char *) alloca (strlen (res->ai_canonname) + 1);
|
|
2412 strcpy (hostname, res->ai_canonname);
|
|
2413
|
|
2414 freeaddrinfo (res);
|
|
2415 }
|
|
2416 # endif /* !(HAVE_GETADDRINFO && HAVE_GETNAMEINFO) */
|
428
|
2417 }
|
|
2418 # endif /* HAVE_SOCKETS */
|
|
2419 Vsystem_name = build_string (hostname);
|
|
2420 #endif /* HAVE_GETHOSTNAME */
|
|
2421 {
|
|
2422 Bufbyte *p;
|
|
2423 Bytecount i;
|
|
2424
|
|
2425 for (i = 0, p = XSTRING_DATA (Vsystem_name);
|
|
2426 i < XSTRING_LENGTH (Vsystem_name);
|
|
2427 i++, p++)
|
|
2428 {
|
|
2429 if (*p == ' ' || *p == '\t')
|
|
2430 *p = '-';
|
|
2431 }
|
|
2432 }
|
|
2433 }
|
|
2434
|
|
2435
|
|
2436 /************************************************************************/
|
|
2437 /* Emulation of select() */
|
|
2438 /************************************************************************/
|
|
2439
|
|
2440 #ifndef HAVE_SELECT
|
|
2441
|
|
2442 ERROR: XEmacs requires a working select().
|
|
2443
|
|
2444 #endif /* not HAVE_SELECT */
|
|
2445
|
|
2446
|
|
2447 /************************************************************************/
|
|
2448 /* Emulation of signal stuff */
|
|
2449 /************************************************************************/
|
|
2450
|
|
2451 /* BSD 4.1 crap deleted. 4.2 was released in 1983, for God's sake! I
|
|
2452 can't imagine that anyone is actually running that OS any more.
|
|
2453 You can't use X under it (I think) because there's no select().
|
|
2454 Anyway, the signal stuff has all been changed. If someone wants to
|
|
2455 get this stuff working again, look in the FSF Emacs sources. */
|
|
2456
|
|
2457 /* POSIX signals support - DJB */
|
|
2458
|
|
2459 #ifdef HAVE_SIGPROCMASK
|
|
2460
|
|
2461 /* #### Is there any reason this is static global rather than local? */
|
|
2462 static struct sigaction new_action, old_action;
|
|
2463
|
|
2464 signal_handler_t
|
|
2465 sys_do_signal (int signal_number, signal_handler_t action)
|
|
2466 {
|
|
2467 #if 0
|
|
2468
|
|
2469 /* XEmacs works better if system calls are *not* restarted.
|
|
2470 This allows C-g to interrupt reads and writes, on most systems.
|
|
2471
|
|
2472 #### Another possibility is to just longjmp() out of the signal
|
|
2473 handler. According to W.R. Stevens, this should be OK on all
|
|
2474 systems. However, I don't want to deal with the potential
|
|
2475 evil ramifications of this at this point. */
|
|
2476
|
|
2477 #ifdef DGUX
|
|
2478 /* This gets us restartable system calls for efficiency.
|
|
2479 The "else" code will work as well. */
|
|
2480 return (berk_signal (signal_number, action));
|
|
2481 #else
|
|
2482 sigemptyset (&new_action.sa_mask);
|
|
2483 new_action.sa_handler = action;
|
|
2484 #if defined (SA_RESTART)
|
|
2485 /* Emacs mostly works better with restartable system services. If this
|
|
2486 * flag exists, we probably want to turn it on here.
|
|
2487 */
|
|
2488 new_action.sa_flags = SA_RESTART;
|
|
2489 #else
|
|
2490 new_action.sa_flags = 0;
|
|
2491 #endif
|
|
2492 sigaction (signal_number, &new_action, &old_action);
|
|
2493 return (old_action.sa_handler);
|
|
2494 #endif /* DGUX */
|
|
2495
|
|
2496 #else /* not 0 */
|
|
2497
|
|
2498 sigemptyset (&new_action.sa_mask);
|
|
2499 new_action.sa_handler = action;
|
|
2500 #if defined (SA_INTERRUPT) /* don't restart system calls, under SunOS */
|
|
2501 new_action.sa_flags = SA_INTERRUPT;
|
|
2502 #else
|
|
2503 new_action.sa_flags = 0;
|
|
2504 #endif
|
|
2505 sigaction (signal_number, &new_action, &old_action);
|
|
2506 return (signal_handler_t) (old_action.sa_handler);
|
|
2507
|
|
2508 #endif /* not 0 */
|
|
2509 }
|
|
2510
|
|
2511 #elif defined (HAVE_SIGBLOCK)
|
|
2512
|
|
2513 /* We use sigvec() rather than signal() if we have it, because
|
|
2514 it lets us specify interruptible system calls. */
|
|
2515 signal_handler_t
|
|
2516 sys_do_signal (int signal_number, signal_handler_t action)
|
|
2517 {
|
|
2518 struct sigvec vec, ovec;
|
|
2519
|
|
2520 vec.sv_handler = action;
|
|
2521 vec.sv_mask = 0;
|
|
2522 #ifdef SV_INTERRUPT /* don't restart system calls */
|
|
2523 vec.sv_flags = SV_INTERRUPT;
|
|
2524 #else
|
|
2525 vec.sv_flags = 0;
|
|
2526 #endif
|
|
2527
|
|
2528 sigvec (signal_number, &vec, &ovec);
|
|
2529
|
|
2530 return (ovec.sv_handler);
|
|
2531 }
|
|
2532
|
|
2533 #endif /* HAVE_SIGBLOCK (HAVE_SIGPROCMASK) */
|
|
2534
|
|
2535
|
|
2536 /************************************************************************/
|
|
2537 /* Emulation of strerror() and errno support */
|
|
2538 /************************************************************************/
|
|
2539
|
|
2540 #ifndef HAVE_STRERROR
|
|
2541
|
|
2542 #if !defined(NeXT) && !defined(__alpha) && !defined(MACH) && !defined(LINUX) && !defined(IRIX) && !defined(__NetBSD__)
|
|
2543 /* Linux added here by Raymond L. Toy <toy@alydar.crd.ge.com> for XEmacs. */
|
|
2544 /* Irix added here by gparker@sni-usa.com for XEmacs. */
|
|
2545 /* NetBSD added here by James R Grinter <jrg@doc.ic.ac.uk> for XEmacs */
|
442
|
2546 extern const char *sys_errlist[];
|
428
|
2547 extern int sys_nerr;
|
|
2548 #endif
|
|
2549
|
|
2550 #ifdef __NetBSD__
|
|
2551 extern char *sys_errlist[];
|
|
2552 extern int sys_nerr;
|
|
2553 #endif
|
|
2554
|
|
2555
|
442
|
2556 const char *
|
428
|
2557 strerror (int errnum)
|
|
2558 {
|
|
2559 if (errnum >= 0 && errnum < sys_nerr)
|
|
2560 return sys_errlist[errnum];
|
442
|
2561 return ((const char *) GETTEXT ("Unknown error"));
|
428
|
2562 }
|
|
2563
|
|
2564 #endif /* ! HAVE_STRERROR */
|
|
2565
|
442
|
2566 #ifdef WIN32_NATIVE
|
428
|
2567
|
|
2568 struct errentry {
|
|
2569 unsigned long oscode; /* Win32 error */
|
|
2570 int errnocode; /* unix errno */
|
|
2571 };
|
|
2572
|
|
2573 static struct errentry errtable[] = {
|
|
2574 { ERROR_INVALID_FUNCTION, EINVAL }, /* 1 */
|
|
2575 { ERROR_FILE_NOT_FOUND, ENOENT }, /* 2 */
|
|
2576 { ERROR_PATH_NOT_FOUND, ENOENT }, /* 3 */
|
|
2577 { ERROR_TOO_MANY_OPEN_FILES, EMFILE }, /* 4 */
|
|
2578 { ERROR_ACCESS_DENIED, EACCES }, /* 5 */
|
|
2579 { ERROR_INVALID_HANDLE, EBADF }, /* 6 */
|
|
2580 { ERROR_ARENA_TRASHED, ENOMEM }, /* 7 */
|
|
2581 { ERROR_NOT_ENOUGH_MEMORY, ENOMEM }, /* 8 */
|
|
2582 { ERROR_INVALID_BLOCK, ENOMEM }, /* 9 */
|
|
2583 { ERROR_BAD_ENVIRONMENT, E2BIG }, /* 10 */
|
|
2584 { ERROR_BAD_FORMAT, ENOEXEC }, /* 11 */
|
|
2585 { ERROR_INVALID_ACCESS, EINVAL }, /* 12 */
|
|
2586 { ERROR_INVALID_DATA, EINVAL }, /* 13 */
|
|
2587 { ERROR_INVALID_DRIVE, ENOENT }, /* 15 */
|
|
2588 { ERROR_CURRENT_DIRECTORY, EACCES }, /* 16 */
|
|
2589 { ERROR_NOT_SAME_DEVICE, EXDEV }, /* 17 */
|
|
2590 { ERROR_NO_MORE_FILES, ENOENT }, /* 18 */
|
|
2591 { ERROR_LOCK_VIOLATION, EACCES }, /* 33 */
|
|
2592 { ERROR_BAD_NETPATH, ENOENT }, /* 53 */
|
|
2593 { ERROR_NETWORK_ACCESS_DENIED, EACCES }, /* 65 */
|
|
2594 { ERROR_BAD_NET_NAME, ENOENT }, /* 67 */
|
|
2595 { ERROR_FILE_EXISTS, EEXIST }, /* 80 */
|
|
2596 { ERROR_CANNOT_MAKE, EACCES }, /* 82 */
|
|
2597 { ERROR_FAIL_I24, EACCES }, /* 83 */
|
|
2598 { ERROR_INVALID_PARAMETER, EINVAL }, /* 87 */
|
|
2599 { ERROR_NO_PROC_SLOTS, EAGAIN }, /* 89 */
|
|
2600 { ERROR_DRIVE_LOCKED, EACCES }, /* 108 */
|
|
2601 { ERROR_BROKEN_PIPE, EPIPE }, /* 109 */
|
|
2602 { ERROR_DISK_FULL, ENOSPC }, /* 112 */
|
|
2603 { ERROR_INVALID_TARGET_HANDLE, EBADF }, /* 114 */
|
|
2604 { ERROR_INVALID_HANDLE, EINVAL }, /* 124 */
|
|
2605 { ERROR_WAIT_NO_CHILDREN, ECHILD }, /* 128 */
|
|
2606 { ERROR_CHILD_NOT_COMPLETE, ECHILD }, /* 129 */
|
|
2607 { ERROR_DIRECT_ACCESS_HANDLE, EBADF }, /* 130 */
|
|
2608 { ERROR_NEGATIVE_SEEK, EINVAL }, /* 131 */
|
|
2609 { ERROR_SEEK_ON_DEVICE, EACCES }, /* 132 */
|
|
2610 { ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, /* 145 */
|
|
2611 { ERROR_NOT_LOCKED, EACCES }, /* 158 */
|
|
2612 { ERROR_BAD_PATHNAME, ENOENT }, /* 161 */
|
|
2613 { ERROR_MAX_THRDS_REACHED, EAGAIN }, /* 164 */
|
|
2614 { ERROR_LOCK_FAILED, EACCES }, /* 167 */
|
|
2615 { ERROR_ALREADY_EXISTS, EEXIST }, /* 183 */
|
|
2616 { ERROR_FILENAME_EXCED_RANGE, ENOENT }, /* 206 */
|
|
2617 { ERROR_NESTING_NOT_ALLOWED, EAGAIN }, /* 215 */
|
|
2618 { ERROR_NOT_ENOUGH_QUOTA, ENOMEM } /* 1816 */
|
|
2619 };
|
|
2620
|
|
2621 /* The following two constants must be the minimum and maximum
|
|
2622 values in the (contiguous) range of Exec Failure errors. */
|
|
2623 #define MIN_EXEC_ERROR ERROR_INVALID_STARTING_CODESEG
|
|
2624 #define MAX_EXEC_ERROR ERROR_INFLOOP_IN_RELOC_CHAIN
|
|
2625
|
|
2626 /* These are the low and high value in the range of errors that are
|
|
2627 access violations */
|
|
2628 #define MIN_EACCES_RANGE ERROR_WRITE_PROTECT
|
|
2629 #define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED
|
|
2630
|
|
2631 void
|
|
2632 mswindows_set_errno (unsigned long win32_error)
|
|
2633 {
|
|
2634 int i;
|
|
2635
|
|
2636 /* check the table for the OS error code */
|
440
|
2637 for (i = 0; i < countof (errtable); ++i)
|
428
|
2638 {
|
|
2639 if (win32_error == errtable[i].oscode)
|
|
2640 {
|
|
2641 errno = errtable[i].errnocode;
|
|
2642 return;
|
|
2643 }
|
|
2644 }
|
|
2645
|
|
2646 /* The error code wasn't in the table. We check for a range of
|
|
2647 * EACCES errors or exec failure errors (ENOEXEC). Otherwise EINVAL is
|
|
2648 * returned. */
|
|
2649 if (win32_error >= MIN_EACCES_RANGE && win32_error <= MAX_EACCES_RANGE)
|
|
2650 errno = EACCES;
|
|
2651 else if (win32_error >= MIN_EXEC_ERROR && win32_error <= MAX_EXEC_ERROR)
|
|
2652 errno = ENOEXEC;
|
|
2653 else
|
|
2654 errno = EINVAL;
|
|
2655 }
|
|
2656
|
|
2657 void
|
|
2658 mswindows_set_last_errno (void)
|
|
2659 {
|
|
2660 mswindows_set_errno (GetLastError ());
|
|
2661 }
|
|
2662
|
442
|
2663 #endif /* WIN32_NATIVE */
|
428
|
2664
|
|
2665
|
|
2666 /************************************************************************/
|
|
2667 /* Encapsulations of system calls */
|
|
2668 /************************************************************************/
|
|
2669
|
|
2670 #define PATHNAME_CONVERT_OUT(path) \
|
440
|
2671 TO_EXTERNAL_FORMAT (C_STRING, (path), C_STRING_ALLOCA, (path), Qfile_name);
|
428
|
2672
|
|
2673 /***************** low-level calls ****************/
|
|
2674
|
|
2675 /*
|
|
2676 * On USG systems the system calls are INTERRUPTIBLE by signals
|
|
2677 * that the user program has elected to catch. Thus the system call
|
|
2678 * must be retried in these cases. To handle this without massive
|
|
2679 * changes in the source code, we remap the standard system call names
|
|
2680 * to names for our own functions in sysdep.c that do the system call
|
|
2681 * with retries. Actually, for portability reasons, it is good
|
|
2682 * programming practice, as this example shows, to limit all actual
|
|
2683 * system calls to a single occurrence in the source. Sure, this
|
|
2684 * adds an extra level of function call overhead but it is almost
|
|
2685 * always negligible. Fred Fish, Unisoft Systems Inc.
|
|
2686 */
|
|
2687
|
|
2688 /* Ben sez: read Dick Gabriel's essay about the Worse Is Better
|
|
2689 approach to programming and its connection to the silly
|
|
2690 interruptible-system-call business. To find it, look on
|
|
2691 Jamie's home page (http://www.jwz.org/worse-is-better.html). */
|
|
2692
|
|
2693 #ifdef ENCAPSULATE_OPEN
|
|
2694 int
|
442
|
2695 sys_open (const char *path, int oflag, ...)
|
428
|
2696 {
|
|
2697 int mode;
|
|
2698 va_list ap;
|
|
2699
|
|
2700 va_start (ap, oflag);
|
|
2701 mode = va_arg (ap, int);
|
|
2702 va_end (ap);
|
|
2703
|
442
|
2704 PATHNAME_CONVERT_OUT (path);
|
|
2705
|
|
2706 #ifdef WIN32_NATIVE
|
428
|
2707 /* Make all handles non-inheritable */
|
440
|
2708 oflag |= _O_NOINHERIT;
|
|
2709 #endif
|
|
2710
|
|
2711 #ifdef INTERRUPTIBLE_OPEN
|
428
|
2712 {
|
|
2713 int rtnval;
|
|
2714 while ((rtnval = open (path, oflag, mode)) == -1
|
|
2715 && (errno == EINTR))
|
|
2716 DO_NOTHING;
|
|
2717 return rtnval;
|
|
2718 }
|
|
2719 #else
|
|
2720 return open (path, oflag, mode);
|
|
2721 #endif
|
|
2722 }
|
|
2723 #endif /* ENCAPSULATE_OPEN */
|
|
2724
|
|
2725 /* Like sys_open, only when open() is interrupted by EINTR, check for
|
|
2726 QUIT. This allows the callers of this function to be interrupted
|
|
2727 with C-g when, say, reading from named pipes. However, this should
|
|
2728 be used with caution, as it can GC.
|
|
2729
|
|
2730 This function will not function as expected on systems where open()
|
|
2731 is not interrupted by C-g. However, the worst that can happen is
|
|
2732 the fallback to simple open(). */
|
|
2733 int
|
442
|
2734 interruptible_open (const char *path, int oflag, int mode)
|
428
|
2735 {
|
|
2736 /* This function can GC */
|
|
2737 size_t len = strlen (path);
|
|
2738 char *nonreloc = (char *) alloca (len + 1);
|
|
2739
|
|
2740 /* Must copy PATH, because it might be the data of a Lisp_String,
|
|
2741 which could be relocated by GC when checking for QUIT. */
|
|
2742 memcpy (nonreloc, path, len + 1);
|
|
2743
|
|
2744 PATHNAME_CONVERT_OUT (nonreloc);
|
|
2745
|
442
|
2746 #ifdef WIN32_NATIVE
|
440
|
2747 /* Make all handles non-inheritable */
|
|
2748 oflag |= _O_NOINHERIT;
|
|
2749 #endif
|
|
2750
|
428
|
2751 for (;;)
|
|
2752 {
|
|
2753 int rtnval = open (nonreloc, oflag, mode);
|
|
2754 if (!(rtnval == -1 && errno == EINTR))
|
|
2755 return rtnval;
|
|
2756 /* open() was interrupted. Was QUIT responsible? */
|
|
2757 QUIT;
|
|
2758 }
|
|
2759 }
|
|
2760
|
|
2761 #ifdef ENCAPSULATE_CLOSE
|
|
2762 int
|
|
2763 sys_close (int filedes)
|
|
2764 {
|
|
2765 #ifdef INTERRUPTIBLE_CLOSE
|
|
2766 int did_retry = 0;
|
|
2767 REGISTER int rtnval;
|
|
2768
|
|
2769 while ((rtnval = close (filedes)) == -1
|
|
2770 && (errno == EINTR))
|
|
2771 did_retry = 1;
|
|
2772
|
|
2773 /* If close is interrupted SunOS 4.1 may or may not have closed the
|
|
2774 file descriptor. If it did the second close will fail with
|
|
2775 errno = EBADF. That means we have succeeded. */
|
|
2776 if (rtnval == -1 && did_retry && errno == EBADF)
|
|
2777 return 0;
|
|
2778
|
|
2779 return rtnval;
|
|
2780 #else
|
|
2781 return close (filedes);
|
|
2782 #endif
|
|
2783 }
|
|
2784 #endif /* ENCAPSULATE_CLOSE */
|
|
2785
|
|
2786 ssize_t
|
|
2787 sys_read_1 (int fildes, void *buf, size_t nbyte, int allow_quit)
|
|
2788 {
|
|
2789 ssize_t rtnval;
|
|
2790
|
|
2791 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */
|
|
2792 while ((rtnval = read (fildes, buf, nbyte)) == -1
|
|
2793 && (errno == EINTR))
|
|
2794 {
|
|
2795 if (allow_quit)
|
|
2796 REALLY_QUIT;
|
|
2797 }
|
|
2798 return rtnval;
|
|
2799 }
|
|
2800
|
|
2801 #ifdef ENCAPSULATE_READ
|
|
2802 ssize_t
|
|
2803 sys_read (int fildes, void *buf, size_t nbyte)
|
|
2804 {
|
|
2805 return sys_read_1 (fildes, buf, nbyte, 0);
|
|
2806 }
|
|
2807 #endif /* ENCAPSULATE_READ */
|
|
2808
|
|
2809 ssize_t
|
442
|
2810 sys_write_1 (int fildes, const void *buf, size_t nbyte, int allow_quit)
|
428
|
2811 {
|
|
2812 ssize_t bytes_written = 0;
|
442
|
2813 const char *b = (const char *) buf;
|
428
|
2814
|
|
2815 /* No harm in looping regardless of the INTERRUPTIBLE_IO setting. */
|
|
2816 while (nbyte > 0)
|
|
2817 {
|
|
2818 ssize_t rtnval = write (fildes, b, nbyte);
|
|
2819
|
|
2820 if (allow_quit)
|
|
2821 REALLY_QUIT;
|
|
2822
|
|
2823 if (rtnval == -1)
|
|
2824 {
|
|
2825 if (errno == EINTR)
|
|
2826 continue;
|
|
2827 else
|
|
2828 return bytes_written ? bytes_written : -1;
|
|
2829 }
|
|
2830 b += rtnval;
|
|
2831 nbyte -= rtnval;
|
|
2832 bytes_written += rtnval;
|
|
2833 }
|
|
2834 return bytes_written;
|
|
2835 }
|
|
2836
|
|
2837 #ifdef ENCAPSULATE_WRITE
|
|
2838 ssize_t
|
442
|
2839 sys_write (int fildes, const void *buf, size_t nbyte)
|
428
|
2840 {
|
|
2841 return sys_write_1 (fildes, buf, nbyte, 0);
|
|
2842 }
|
|
2843 #endif /* ENCAPSULATE_WRITE */
|
|
2844
|
|
2845
|
|
2846 /**************** stdio calls ****************/
|
|
2847
|
|
2848 /* There is at least some evidence that the stdio calls are interruptible
|
|
2849 just like the normal system calls, at least on some systems. In any
|
|
2850 case, it doesn't hurt to encapsulate them. */
|
|
2851
|
|
2852 /* #### Should also encapsulate fflush().
|
|
2853 #### Should conceivably encapsulate getchar() etc. What a pain! */
|
|
2854
|
|
2855 #ifdef ENCAPSULATE_FOPEN
|
|
2856 FILE *
|
442
|
2857 sys_fopen (const char *path, const char *type)
|
428
|
2858 {
|
|
2859 PATHNAME_CONVERT_OUT (path);
|
442
|
2860 #if defined (WIN32_NATIVE)
|
428
|
2861 {
|
|
2862 int fd;
|
|
2863 int oflag;
|
|
2864 const char * type_save = type;
|
|
2865
|
|
2866 /* Force all file handles to be non-inheritable. This is necessary to
|
|
2867 ensure child processes don't unwittingly inherit handles that might
|
|
2868 prevent future file access. */
|
|
2869
|
|
2870 if (type[0] == 'r')
|
|
2871 oflag = O_RDONLY;
|
|
2872 else if (type[0] == 'w' || type[0] == 'a')
|
|
2873 oflag = O_WRONLY | O_CREAT | O_TRUNC;
|
|
2874 else
|
|
2875 return 0;
|
|
2876
|
|
2877 /* Only do simplistic option parsing. */
|
|
2878 while (*++type)
|
|
2879 if (type[0] == '+')
|
|
2880 {
|
|
2881 oflag &= ~(O_RDONLY | O_WRONLY);
|
|
2882 oflag |= O_RDWR;
|
|
2883 }
|
|
2884 else if (type[0] == 'b')
|
|
2885 {
|
|
2886 oflag &= ~O_TEXT;
|
|
2887 oflag |= O_BINARY;
|
|
2888 }
|
|
2889 else if (type[0] == 't')
|
|
2890 {
|
|
2891 oflag &= ~O_BINARY;
|
|
2892 oflag |= O_TEXT;
|
|
2893 }
|
|
2894 else break;
|
|
2895
|
|
2896 fd = open (path, oflag | _O_NOINHERIT, 0644);
|
|
2897 if (fd < 0)
|
|
2898 return NULL;
|
|
2899
|
|
2900 return _fdopen (fd, type_save);
|
|
2901 }
|
|
2902 #elif defined (INTERRUPTIBLE_OPEN)
|
|
2903 {
|
|
2904 FILE *rtnval;
|
|
2905 while (!(rtnval = fopen (path, type)) && (errno == EINTR))
|
|
2906 DO_NOTHING;
|
|
2907 return rtnval;
|
|
2908 }
|
|
2909 #else
|
|
2910 return fopen (path, type);
|
|
2911 #endif
|
|
2912 }
|
|
2913 #endif /* ENCAPSULATE_FOPEN */
|
|
2914
|
|
2915
|
|
2916 #ifdef ENCAPSULATE_FCLOSE
|
|
2917 int
|
|
2918 sys_fclose (FILE *stream)
|
|
2919 {
|
|
2920 #ifdef INTERRUPTIBLE_CLOSE
|
|
2921 int rtnval;
|
|
2922
|
|
2923 while ((rtnval = fclose (stream)) == EOF
|
|
2924 && (errno == EINTR))
|
|
2925 ;
|
|
2926 return rtnval;
|
|
2927 #else
|
|
2928 return fclose (stream);
|
|
2929 #endif
|
|
2930 }
|
|
2931 #endif /* ENCAPSULATE_FCLOSE */
|
|
2932
|
|
2933
|
|
2934 #ifdef ENCAPSULATE_FREAD
|
|
2935 size_t
|
|
2936 sys_fread (void *ptr, size_t size, size_t nitem, FILE *stream)
|
|
2937 {
|
|
2938 #ifdef INTERRUPTIBLE_IO
|
|
2939 size_t rtnval;
|
|
2940 size_t items_read = 0;
|
|
2941 char *b = (char *) ptr;
|
|
2942
|
|
2943 while (nitem > 0)
|
|
2944 {
|
|
2945 rtnval = fread (b, size, nitem, stream);
|
|
2946 if (rtnval == 0)
|
|
2947 {
|
|
2948 if (ferror (stream) && errno == EINTR)
|
|
2949 continue;
|
|
2950 else
|
|
2951 return items_read;
|
|
2952 }
|
|
2953 b += size*rtnval;
|
|
2954 nitem -= rtnval;
|
|
2955 items_read += rtnval;
|
|
2956 }
|
|
2957 return (items_read);
|
|
2958 #else
|
|
2959 return fread (ptr, size, nitem, stream);
|
|
2960 #endif
|
|
2961 }
|
|
2962 #endif /* ENCAPSULATE_FREAD */
|
|
2963
|
|
2964
|
|
2965 #ifdef ENCAPSULATE_FWRITE
|
|
2966 size_t
|
442
|
2967 sys_fwrite (const void *ptr, size_t size, size_t nitem, FILE *stream)
|
428
|
2968 {
|
|
2969 #ifdef INTERRUPTIBLE_IO
|
|
2970 size_t rtnval;
|
|
2971 size_t items_written = 0;
|
442
|
2972 const char *b = (const char *) ptr;
|
428
|
2973
|
|
2974 while (nitem > 0)
|
|
2975 {
|
|
2976 rtnval = fwrite (b, size, nitem, stream);
|
|
2977 if (rtnval == 0)
|
|
2978 {
|
|
2979 if (ferror (stream) && errno == EINTR)
|
|
2980 continue;
|
|
2981 else
|
|
2982 return items_written;
|
|
2983 }
|
|
2984 b += size*rtnval;
|
|
2985 nitem -= rtnval;
|
|
2986 items_written += rtnval;
|
|
2987 }
|
|
2988 return (items_written);
|
|
2989 #else
|
|
2990 return fwrite (ptr, size, nitem, stream);
|
|
2991 #endif
|
|
2992 }
|
|
2993 #endif /* ENCAPSULATE_FWRITE */
|
|
2994
|
|
2995
|
|
2996 /********************* directory calls *******************/
|
|
2997
|
|
2998 #ifdef ENCAPSULATE_CHDIR
|
|
2999 int
|
442
|
3000 sys_chdir (const char *path)
|
428
|
3001 {
|
|
3002 PATHNAME_CONVERT_OUT (path);
|
|
3003 return chdir (path);
|
|
3004 }
|
|
3005 #endif /* ENCAPSULATE_CHDIR */
|
|
3006
|
|
3007
|
|
3008 #ifdef ENCAPSULATE_MKDIR
|
|
3009 int
|
442
|
3010 sys_mkdir (const char *path, mode_t mode)
|
428
|
3011 {
|
|
3012 PATHNAME_CONVERT_OUT (path);
|
442
|
3013 #ifdef WIN32_NATIVE
|
428
|
3014 return mkdir (path);
|
|
3015 #else
|
|
3016 return mkdir (path, mode);
|
|
3017 #endif
|
|
3018 }
|
|
3019 #endif /* ENCAPSULATE_MKDIR */
|
|
3020
|
|
3021
|
|
3022 #ifdef ENCAPSULATE_OPENDIR
|
|
3023 DIR *
|
442
|
3024 sys_opendir (const char *filename)
|
428
|
3025 {
|
|
3026 DIR *rtnval;
|
|
3027 PATHNAME_CONVERT_OUT (filename);
|
|
3028
|
|
3029 while (!(rtnval = opendir (filename))
|
|
3030 && (errno == EINTR))
|
|
3031 ;
|
|
3032 return rtnval;
|
|
3033 }
|
|
3034 #endif /* ENCAPSULATE_OPENDIR */
|
|
3035
|
|
3036
|
|
3037 #ifdef ENCAPSULATE_READDIR
|
|
3038 DIRENTRY *
|
|
3039 sys_readdir (DIR *dirp)
|
|
3040 {
|
|
3041 DIRENTRY *rtnval;
|
|
3042
|
|
3043 /* Apparently setting errno is necessary on some systems?
|
|
3044 Maybe readdir() doesn't always set errno ?! */
|
|
3045 while (!(errno = 0, rtnval = readdir (dirp))
|
|
3046 && (errno == EINTR))
|
|
3047 ;
|
|
3048 #ifndef MULE
|
|
3049 return rtnval;
|
|
3050 #else /* MULE */
|
|
3051 if (rtnval == NULL) /* End of directory */
|
|
3052 return NULL;
|
|
3053 {
|
442
|
3054 const Extbyte * const external_name = (const Extbyte *) rtnval->d_name;
|
462
|
3055 Extcount external_len = strlen (rtnval->d_name);
|
|
3056 const Bufbyte *internal_name;
|
|
3057 Bytecount internal_len;
|
513
|
3058
|
462
|
3059 TO_INTERNAL_FORMAT (DATA, (external_name, external_len),
|
|
3060 ALLOCA, (internal_name, internal_len),
|
|
3061 Qfile_name);
|
|
3062
|
|
3063 /* check for common case of ASCII filename */
|
|
3064 if (internal_len == external_len &&
|
|
3065 !memcmp (external_name, internal_name, internal_len))
|
428
|
3066 return rtnval;
|
|
3067
|
|
3068 { /* Non-ASCII filename */
|
|
3069 static Bufbyte_dynarr *internal_DIRENTRY;
|
|
3070 if (!internal_DIRENTRY)
|
|
3071 internal_DIRENTRY = Dynarr_new (Bufbyte);
|
|
3072 else
|
|
3073 Dynarr_reset (internal_DIRENTRY);
|
|
3074
|
|
3075 Dynarr_add_many (internal_DIRENTRY, (Bufbyte *) rtnval,
|
|
3076 offsetof (DIRENTRY, d_name));
|
|
3077
|
|
3078
|
|
3079 Dynarr_add_many (internal_DIRENTRY, internal_name, internal_len);
|
444
|
3080 Dynarr_add (internal_DIRENTRY, '\0'); /* NUL-terminate */
|
428
|
3081 return (DIRENTRY *) Dynarr_atp (internal_DIRENTRY, 0);
|
|
3082 }
|
|
3083 }
|
|
3084 #endif /* MULE */
|
|
3085 }
|
|
3086 #endif /* ENCAPSULATE_READDIR */
|
|
3087
|
|
3088
|
|
3089 #ifdef ENCAPSULATE_CLOSEDIR
|
|
3090 int
|
|
3091 sys_closedir (DIR *dirp)
|
|
3092 {
|
|
3093 int rtnval;
|
|
3094
|
|
3095 while ((rtnval = closedir (dirp)) == -1
|
|
3096 && (errno == EINTR))
|
|
3097 ;
|
|
3098 return rtnval;
|
|
3099 }
|
|
3100 #endif /* ENCAPSULATE_CLOSEDIR */
|
|
3101
|
|
3102
|
|
3103 #ifdef ENCAPSULATE_RMDIR
|
|
3104 int
|
442
|
3105 sys_rmdir (const char *path)
|
428
|
3106 {
|
|
3107 PATHNAME_CONVERT_OUT (path);
|
|
3108 return rmdir (path);
|
|
3109 }
|
|
3110 #endif /* ENCAPSULATE_RMDIR */
|
|
3111
|
|
3112
|
|
3113 /***************** file-information calls ******************/
|
|
3114
|
|
3115 #ifdef ENCAPSULATE_ACCESS
|
|
3116 int
|
442
|
3117 sys_access (const char *path, int mode)
|
428
|
3118 {
|
|
3119 PATHNAME_CONVERT_OUT (path);
|
|
3120 return access (path, mode);
|
|
3121 }
|
|
3122 #endif /* ENCAPSULATE_ACCESS */
|
|
3123
|
|
3124
|
|
3125 #ifdef HAVE_EACCESS
|
|
3126 #ifdef ENCAPSULATE_EACCESS
|
|
3127 int
|
442
|
3128 sys_eaccess (const char *path, int mode)
|
428
|
3129 {
|
|
3130 PATHNAME_CONVERT_OUT (path);
|
|
3131 return eaccess (path, mode);
|
|
3132 }
|
|
3133 #endif /* ENCAPSULATE_EACCESS */
|
|
3134 #endif /* HAVE_EACCESS */
|
|
3135
|
|
3136
|
|
3137 #ifdef ENCAPSULATE_LSTAT
|
|
3138 int
|
442
|
3139 sys_lstat (const char *path, struct stat *buf)
|
428
|
3140 {
|
|
3141 PATHNAME_CONVERT_OUT (path);
|
|
3142 return lstat (path, buf);
|
|
3143 }
|
|
3144 #endif /* ENCAPSULATE_LSTAT */
|
|
3145
|
|
3146
|
|
3147 #ifdef ENCAPSULATE_READLINK
|
|
3148 int
|
442
|
3149 sys_readlink (const char *path, char *buf, size_t bufsiz)
|
428
|
3150 {
|
|
3151 PATHNAME_CONVERT_OUT (path);
|
|
3152 /* #### currently we don't do conversions on the incoming data */
|
|
3153 return readlink (path, buf, bufsiz);
|
|
3154 }
|
|
3155 #endif /* ENCAPSULATE_READLINK */
|
|
3156
|
432
|
3157 #ifdef ENCAPSULATE_FSTAT
|
|
3158 int
|
|
3159 sys_fstat (int fd, struct stat *buf)
|
|
3160 {
|
442
|
3161 #ifdef WIN32_NATIVE
|
|
3162 return mswindows_fstat (fd, buf);
|
|
3163 #else
|
432
|
3164 return fstat (fd, buf);
|
442
|
3165 #endif
|
432
|
3166 }
|
|
3167 #endif /* ENCAPSULATE_FSTAT */
|
|
3168
|
428
|
3169 int
|
442
|
3170 xemacs_stat (const char *path, struct stat *buf)
|
428
|
3171 {
|
|
3172 PATHNAME_CONVERT_OUT (path);
|
442
|
3173 #ifdef WIN32_NATIVE
|
|
3174 return mswindows_stat (path, buf);
|
|
3175 #else
|
428
|
3176 return stat (path, buf);
|
442
|
3177 #endif
|
428
|
3178 }
|
|
3179
|
|
3180 /****************** file-manipulation calls *****************/
|
|
3181
|
|
3182 #ifdef ENCAPSULATE_CHMOD
|
|
3183 int
|
442
|
3184 sys_chmod (const char *path, mode_t mode)
|
428
|
3185 {
|
|
3186 PATHNAME_CONVERT_OUT (path);
|
|
3187 return chmod (path, mode);
|
|
3188 }
|
|
3189 #endif /* ENCAPSULATE_CHMOD */
|
|
3190
|
|
3191
|
|
3192 #ifdef ENCAPSULATE_CREAT
|
|
3193 int
|
442
|
3194 sys_creat (const char *path, mode_t mode)
|
428
|
3195 {
|
|
3196 PATHNAME_CONVERT_OUT (path);
|
|
3197 return creat (path, mode);
|
|
3198 }
|
|
3199 #endif /* ENCAPSULATE_CREAT */
|
|
3200
|
|
3201
|
|
3202 #ifdef ENCAPSULATE_LINK
|
|
3203 int
|
442
|
3204 sys_link (const char *existing, const char *new)
|
428
|
3205 {
|
|
3206 PATHNAME_CONVERT_OUT (existing);
|
|
3207 PATHNAME_CONVERT_OUT (new);
|
|
3208 return link (existing, new);
|
|
3209 }
|
|
3210 #endif /* ENCAPSULATE_LINK */
|
|
3211
|
|
3212
|
|
3213 #ifdef ENCAPSULATE_RENAME
|
|
3214 int
|
442
|
3215 sys_rename (const char *old, const char *new)
|
428
|
3216 {
|
|
3217 PATHNAME_CONVERT_OUT (old);
|
|
3218 PATHNAME_CONVERT_OUT (new);
|
442
|
3219 #ifdef WIN32_NATIVE
|
428
|
3220 /* Windows rename fails if NEW exists */
|
|
3221 if (rename (old, new) == 0)
|
|
3222 return 0;
|
|
3223 if (errno != EEXIST)
|
|
3224 return -1;
|
|
3225 unlink (new);
|
442
|
3226 #endif /* WIN32_NATIVE */
|
428
|
3227 return rename (old, new);
|
|
3228 }
|
|
3229 #endif /* ENCAPSULATE_RENAME */
|
|
3230
|
|
3231
|
|
3232 #ifdef ENCAPSULATE_SYMLINK
|
|
3233 int
|
442
|
3234 sys_symlink (const char *name1, const char *name2)
|
428
|
3235 {
|
|
3236 PATHNAME_CONVERT_OUT (name1);
|
|
3237 PATHNAME_CONVERT_OUT (name2);
|
|
3238 return symlink (name1, name2);
|
|
3239 }
|
|
3240 #endif /* ENCAPSULATE_SYMLINK */
|
|
3241
|
|
3242
|
|
3243 #ifdef ENCAPSULATE_UNLINK
|
|
3244 int
|
442
|
3245 sys_unlink (const char *path)
|
428
|
3246 {
|
|
3247 PATHNAME_CONVERT_OUT (path);
|
|
3248 return unlink (path);
|
|
3249 }
|
|
3250 #endif /* ENCAPSULATE_UNLINK */
|
|
3251
|
|
3252
|
|
3253 #ifdef ENCAPSULATE_EXECVP
|
|
3254 int
|
442
|
3255 sys_execvp (const char *path, char * const * argv)
|
428
|
3256 {
|
|
3257 int i, argc;
|
|
3258 char ** new_argv;
|
|
3259
|
|
3260 PATHNAME_CONVERT_OUT (path);
|
|
3261 for (argc = 0; argv[argc]; argc++)
|
|
3262 ;
|
|
3263 new_argv = alloca_array (char *, argc + 1);
|
|
3264 for (i = 0; i < argc; i++)
|
|
3265 {
|
|
3266 new_argv[i] = argv[i];
|
|
3267 PATHNAME_CONVERT_OUT (new_argv[i]);
|
|
3268 }
|
|
3269 new_argv[argc] = NULL;
|
|
3270 return execvp (path, new_argv);
|
|
3271 }
|
|
3272 #endif /* ENCAPSULATE_EXECVP */
|
|
3273
|
|
3274
|
|
3275 /************************************************************************/
|
|
3276 /* Emulations of missing system calls */
|
|
3277 /************************************************************************/
|
|
3278
|
|
3279 /***** (these are primarily required for USG, it seems) *****/
|
|
3280
|
|
3281 #ifndef HAVE_GETCWD
|
|
3282 char *
|
442
|
3283 getcwd (char *pathname, size_t size)
|
428
|
3284 {
|
|
3285 return getwd (pathname);
|
|
3286 }
|
|
3287 #endif /* emulate getcwd */
|
|
3288
|
|
3289
|
|
3290 #if 0 /* mrb */
|
|
3291 /*
|
|
3292 * Warning, this function may not duplicate BSD 4.2 action properly
|
|
3293 * under error conditions.
|
|
3294 */
|
|
3295
|
|
3296 #ifndef HAVE_GETWD
|
|
3297 char *
|
|
3298 getwd (char *pathname)
|
|
3299 {
|
|
3300 char *npath, *spath;
|
|
3301 #if !__STDC__ && !defined(STDC_HEADERS)
|
|
3302 extern char *getcwd ();
|
|
3303 #endif
|
|
3304
|
|
3305 spath = npath = getcwd ((char *) 0, MAXPATHLEN);
|
|
3306 if (spath == 0)
|
|
3307 return spath;
|
|
3308 /* On Altos 3068, getcwd can return @hostname/dir, so discard
|
|
3309 up to first slash. Should be harmless on other systems. */
|
|
3310 while (*npath && *npath != '/')
|
|
3311 npath++;
|
|
3312 strcpy (pathname, npath);
|
|
3313 xfree (spath); /* getcwd uses malloc */
|
|
3314 return pathname;
|
|
3315 }
|
|
3316 #endif /* HAVE_GETWD */
|
|
3317 #endif /* 0 - mrb */
|
|
3318
|
|
3319 /*
|
|
3320 * Emulate rename using unlink/link. Note that this is
|
|
3321 * only partially correct. Also, doesn't enforce restriction
|
|
3322 * that files be of same type (regular->regular, dir->dir, etc).
|
|
3323 */
|
|
3324
|
|
3325 #ifndef HAVE_RENAME
|
|
3326 int
|
442
|
3327 rename (const char *from, const char *to)
|
428
|
3328 {
|
|
3329 if (access (from, 0) == 0)
|
|
3330 {
|
|
3331 unlink (to);
|
|
3332 if (link (from, to) == 0)
|
|
3333 if (unlink (from) == 0)
|
|
3334 return (0);
|
|
3335 }
|
|
3336 return (-1);
|
|
3337 }
|
|
3338 #endif /* HAVE_RENAME */
|
|
3339
|
|
3340 #ifdef HPUX
|
|
3341 #ifndef HAVE_PERROR
|
|
3342
|
|
3343 /* HPUX curses library references perror, but as far as we know
|
|
3344 it won't be called. Anyway this definition will do for now. */
|
|
3345
|
|
3346 perror (void)
|
|
3347 {
|
|
3348 }
|
|
3349
|
|
3350 #endif /* not HAVE_PERROR */
|
|
3351 #endif /* HPUX */
|
|
3352
|
|
3353 #ifndef HAVE_DUP2
|
|
3354
|
|
3355 /*
|
|
3356 * Emulate BSD dup2. First close newd if it already exists.
|
|
3357 * Then, attempt to dup oldd. If not successful, call dup2 recursively
|
|
3358 * until we are, then close the unsuccessful ones.
|
|
3359 */
|
|
3360
|
|
3361 int
|
|
3362 dup2 (int oldd, int newd)
|
|
3363 {
|
|
3364 int fd, ret;
|
|
3365
|
|
3366 sys_close (newd);
|
|
3367
|
|
3368 #ifdef F_DUPFD
|
|
3369 fd = fcntl (oldd, F_DUPFD, newd);
|
|
3370 if (fd != newd)
|
|
3371 error ("can't dup2 (%i,%i) : %s", oldd, newd, strerror (errno));
|
|
3372 #else
|
|
3373 fd = dup (old);
|
|
3374 if (fd == -1)
|
|
3375 return -1;
|
|
3376 if (fd == new)
|
|
3377 return new;
|
|
3378 ret = dup2 (old, new);
|
|
3379 sys_close (fd);
|
|
3380 return ret;
|
|
3381 #endif /* F_DUPFD */
|
|
3382 }
|
|
3383
|
|
3384 #endif /* not HAVE_DUP2 */
|
|
3385
|
|
3386 /*
|
|
3387 * Gettimeofday. Simulate as much as possible. Only accurate
|
|
3388 * to nearest second. Emacs doesn't use tzp so ignore it for now.
|
|
3389 */
|
|
3390
|
|
3391 #if !defined (HAVE_GETTIMEOFDAY)
|
|
3392
|
|
3393 int
|
|
3394 gettimeofday (struct timeval *tp, struct timezone *tzp)
|
|
3395 {
|
|
3396 extern long time ();
|
|
3397
|
|
3398 tp->tv_sec = time ((long *)0);
|
|
3399 tp->tv_usec = 0;
|
|
3400 if (tzp != 0)
|
|
3401 tzp->tz_minuteswest = -1;
|
|
3402 return (0);
|
|
3403 }
|
|
3404
|
|
3405 #endif /* !HAVE_GETTIMEOFDAY */
|
|
3406
|
|
3407 /* No need to encapsulate utime and utimes explicitly because all
|
|
3408 access to those functions goes through the following. */
|
|
3409
|
|
3410 int
|
|
3411 set_file_times (char *filename, EMACS_TIME atime, EMACS_TIME mtime)
|
|
3412 {
|
460
|
3413 #if defined (HAVE_UTIME)
|
|
3414 struct utimbuf utb;
|
|
3415 utb.actime = EMACS_SECS (atime);
|
|
3416 utb.modtime = EMACS_SECS (mtime);
|
|
3417 return utime (filename, &utb);
|
|
3418 #elif defined (HAVE_UTIMES)
|
428
|
3419 struct timeval tv[2];
|
|
3420 tv[0] = atime;
|
|
3421 tv[1] = mtime;
|
|
3422 return utimes (filename, tv);
|
460
|
3423 #else
|
|
3424 /* No file times setting function available. */
|
|
3425 return -1;
|
|
3426 #endif
|
428
|
3427 }
|
|
3428
|
|
3429 /* */
|
|
3430
|
|
3431 static long ticks_per_second;
|
|
3432 static long orig_user_ticks, orig_system_ticks;
|
|
3433 EMACS_TIME orig_real_time;
|
|
3434
|
|
3435 static int process_times_available;
|
|
3436
|
|
3437 /* Return the relative user and system tick count. We try to
|
|
3438 maintain calculations in terms of integers as long as possible
|
|
3439 for increased accuracy. */
|
|
3440
|
|
3441 static int
|
|
3442 get_process_times_1 (long *user_ticks, long *system_ticks)
|
|
3443 {
|
442
|
3444 #if defined (_SC_CLK_TCK) || defined (CLK_TCK) && !defined(WIN32_NATIVE)
|
428
|
3445 /* We have the POSIX times() function available. */
|
|
3446 struct tms tttt;
|
|
3447 times (&tttt);
|
|
3448 *user_ticks = (long) tttt.tms_utime;
|
|
3449 *system_ticks = (long) tttt.tms_stime;
|
|
3450 return 1;
|
|
3451 #elif defined (CLOCKS_PER_SEC)
|
|
3452 *user_ticks = (long) clock ();
|
|
3453 *system_ticks = 0;
|
|
3454 return 1;
|
|
3455 #else
|
|
3456 return 0;
|
|
3457 #endif
|
|
3458 }
|
|
3459
|
|
3460 void
|
|
3461 init_process_times_very_early (void)
|
|
3462 {
|
|
3463 #if defined (_SC_CLK_TCK)
|
|
3464 ticks_per_second = sysconf (_SC_CLK_TCK);
|
|
3465 #elif defined (CLK_TCK)
|
|
3466 ticks_per_second = CLK_TCK;
|
|
3467 #elif defined (CLOCKS_PER_SEC)
|
|
3468 ticks_per_second = CLOCKS_PER_SEC;
|
|
3469 #endif
|
|
3470
|
|
3471 process_times_available = get_process_times_1 (&orig_user_ticks,
|
|
3472 &orig_system_ticks);
|
|
3473 EMACS_GET_TIME (orig_real_time);
|
|
3474 }
|
|
3475
|
|
3476 /* Return the user and system times used up by this process so far. */
|
|
3477 void
|
|
3478 get_process_times (double *user_time, double *system_time, double *real_time)
|
|
3479 {
|
|
3480 EMACS_TIME curr_real_time;
|
|
3481 EMACS_TIME elapsed_time;
|
|
3482 long curr_user_ticks, curr_system_ticks;
|
|
3483
|
|
3484 EMACS_GET_TIME (curr_real_time);
|
|
3485 EMACS_SUB_TIME (elapsed_time, curr_real_time, orig_real_time);
|
|
3486 *real_time = (EMACS_SECS (elapsed_time)
|
|
3487 + ((double) EMACS_USECS (elapsed_time)) / 1000000);
|
|
3488 if (get_process_times_1 (&curr_user_ticks, &curr_system_ticks))
|
|
3489 {
|
|
3490 *user_time = (((double) (curr_user_ticks - orig_user_ticks))
|
|
3491 / ticks_per_second);
|
|
3492 *system_time = (((double) (curr_system_ticks - orig_system_ticks))
|
|
3493 / ticks_per_second);
|
|
3494 }
|
|
3495 else
|
|
3496 {
|
|
3497 /* A lame OS */
|
|
3498 *user_time = *real_time;
|
|
3499 *system_time = 0;
|
|
3500 }
|
|
3501 }
|
|
3502
|
|
3503 #ifndef HAVE_RANDOM
|
|
3504 #ifdef random
|
|
3505 #define HAVE_RANDOM
|
|
3506 #endif
|
|
3507 #endif
|
|
3508
|
|
3509 /* Figure out how many bits the system's random number generator uses.
|
|
3510 `random' and `lrand48' are assumed to return 31 usable bits.
|
|
3511 BSD `rand' returns a 31 bit value but the low order bits are unusable;
|
|
3512 so we'll shift it and treat it like the 15-bit USG `rand'. */
|
|
3513
|
|
3514 #ifndef RAND_BITS
|
|
3515 # ifdef HAVE_RANDOM
|
|
3516 # define RAND_BITS 31
|
|
3517 # else /* !HAVE_RANDOM */
|
|
3518 # ifdef HAVE_LRAND48
|
|
3519 # define RAND_BITS 31
|
|
3520 # define random lrand48
|
|
3521 # else /* !HAVE_LRAND48 */
|
|
3522 # define RAND_BITS 15
|
|
3523 # if RAND_MAX == 32767
|
|
3524 # define random rand
|
|
3525 # else /* RAND_MAX != 32767 */
|
|
3526 # if RAND_MAX == 2147483647
|
|
3527 # define random() (rand () >> 16)
|
|
3528 # else /* RAND_MAX != 2147483647 */
|
|
3529 # ifdef USG
|
|
3530 # define random rand
|
|
3531 # else
|
|
3532 # define random() (rand () >> 16)
|
|
3533 # endif /* !BSD */
|
|
3534 # endif /* RAND_MAX != 2147483647 */
|
|
3535 # endif /* RAND_MAX != 32767 */
|
|
3536 # endif /* !HAVE_LRAND48 */
|
|
3537 # endif /* !HAVE_RANDOM */
|
|
3538 #endif /* !RAND_BITS */
|
|
3539
|
|
3540 void seed_random (long arg);
|
|
3541 void
|
|
3542 seed_random (long arg)
|
|
3543 {
|
|
3544 #ifdef HAVE_RANDOM
|
|
3545 srandom ((unsigned int)arg);
|
|
3546 #else
|
|
3547 # ifdef HAVE_LRAND48
|
|
3548 srand48 (arg);
|
|
3549 # else
|
|
3550 srand ((unsigned int)arg);
|
|
3551 # endif
|
|
3552 #endif
|
|
3553 }
|
|
3554
|
|
3555 /*
|
|
3556 * Build a full Emacs-sized word out of whatever we've got.
|
|
3557 * This suffices even for a 64-bit architecture with a 15-bit rand.
|
|
3558 */
|
|
3559 long get_random (void);
|
|
3560 long
|
|
3561 get_random (void)
|
|
3562 {
|
|
3563 long val = random ();
|
|
3564 #if VALBITS > RAND_BITS
|
|
3565 val = (val << RAND_BITS) ^ random ();
|
|
3566 #if VALBITS > 2*RAND_BITS
|
|
3567 val = (val << RAND_BITS) ^ random ();
|
|
3568 #if VALBITS > 3*RAND_BITS
|
|
3569 val = (val << RAND_BITS) ^ random ();
|
|
3570 #if VALBITS > 4*RAND_BITS
|
|
3571 val = (val << RAND_BITS) ^ random ();
|
|
3572 #endif /* need at least 5 */
|
|
3573 #endif /* need at least 4 */
|
|
3574 #endif /* need at least 3 */
|
|
3575 #endif /* need at least 2 */
|
|
3576 return val & ((1L << VALBITS) - 1);
|
|
3577 }
|
|
3578
|
|
3579
|
|
3580 /************************************************************************/
|
|
3581 /* Strings corresponding to defined signals */
|
|
3582 /************************************************************************/
|
|
3583
|
|
3584 #if !defined (SYS_SIGLIST_DECLARED) && !defined (HAVE_SYS_SIGLIST)
|
|
3585
|
442
|
3586 #if defined(WIN32_NATIVE) || defined(CYGWIN)
|
|
3587 const char *sys_siglist[] =
|
428
|
3588 {
|
|
3589 "bum signal!!",
|
|
3590 "hangup",
|
|
3591 "interrupt",
|
|
3592 "quit",
|
|
3593 "illegal instruction",
|
|
3594 "trace trap",
|
|
3595 "iot instruction",
|
|
3596 "emt instruction",
|
|
3597 "floating point exception",
|
|
3598 "kill",
|
|
3599 "bus error",
|
|
3600 "segmentation violation",
|
|
3601 "bad argument to system call",
|
|
3602 "write on a pipe with no one to read it",
|
|
3603 "alarm clock",
|
|
3604 "software termination signal from kill",
|
|
3605 "status signal",
|
|
3606 "sendable stop signal not from tty",
|
|
3607 "stop signal from tty",
|
|
3608 "continue a stopped process",
|
|
3609 "child status has changed",
|
|
3610 "background read attempted from control tty",
|
|
3611 "background write attempted from control tty",
|
|
3612 "input record available at control tty",
|
|
3613 "exceeded CPU time limit",
|
|
3614 "exceeded file size limit"
|
|
3615 };
|
|
3616 #endif
|
|
3617
|
|
3618 #ifdef USG
|
|
3619 #ifdef AIX
|
442
|
3620 const char *sys_siglist[NSIG + 1] =
|
428
|
3621 {
|
|
3622 /* AIX has changed the signals a bit */
|
|
3623 DEFER_GETTEXT ("bogus signal"), /* 0 */
|
|
3624 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
|
|
3625 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
|
|
3626 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
|
|
3627 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
|
|
3628 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
|
|
3629 DEFER_GETTEXT ("IOT instruction"), /* 6 SIGIOT */
|
|
3630 DEFER_GETTEXT ("crash likely"), /* 7 SIGDANGER */
|
|
3631 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
|
|
3632 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
|
|
3633 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
|
|
3634 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
|
|
3635 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
|
|
3636 DEFER_GETTEXT ("write on a pipe with no one to read it"), /* 13 SIGPIPE */
|
|
3637 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
|
|
3638 DEFER_GETTEXT ("software termination signum"), /* 15 SIGTERM */
|
|
3639 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
|
|
3640 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
|
|
3641 DEFER_GETTEXT ("death of a child"), /* 18 SIGCLD */
|
|
3642 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
|
|
3643 DEFER_GETTEXT ("bogus signal"), /* 20 */
|
|
3644 DEFER_GETTEXT ("bogus signal"), /* 21 */
|
|
3645 DEFER_GETTEXT ("bogus signal"), /* 22 */
|
|
3646 DEFER_GETTEXT ("bogus signal"), /* 23 */
|
|
3647 DEFER_GETTEXT ("bogus signal"), /* 24 */
|
|
3648 DEFER_GETTEXT ("LAN I/O interrupt"), /* 25 SIGAIO */
|
|
3649 DEFER_GETTEXT ("PTY I/O interrupt"), /* 26 SIGPTY */
|
|
3650 DEFER_GETTEXT ("I/O intervention required"), /* 27 SIGIOINT */
|
|
3651 #ifdef AIXHFT
|
|
3652 DEFER_GETTEXT ("HFT grant"), /* 28 SIGGRANT */
|
|
3653 DEFER_GETTEXT ("HFT retract"), /* 29 SIGRETRACT */
|
|
3654 DEFER_GETTEXT ("HFT sound done"), /* 30 SIGSOUND */
|
|
3655 DEFER_GETTEXT ("HFT input ready"), /* 31 SIGMSG */
|
|
3656 #endif
|
|
3657 0
|
|
3658 };
|
|
3659 #else /* USG, not AIX */
|
442
|
3660 const char *sys_siglist[NSIG + 1] =
|
428
|
3661 {
|
|
3662 DEFER_GETTEXT ("bogus signal"), /* 0 */
|
|
3663 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
|
|
3664 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
|
|
3665 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
|
|
3666 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
|
|
3667 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
|
|
3668 DEFER_GETTEXT ("IOT instruction"), /* 6 SIGIOT */
|
|
3669 DEFER_GETTEXT ("EMT instruction"), /* 7 SIGEMT */
|
|
3670 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
|
|
3671 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
|
|
3672 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
|
|
3673 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
|
|
3674 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
|
|
3675 DEFER_GETTEXT ("write on a pipe with no one to read it"), /* 13 SIGPIPE */
|
|
3676 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
|
|
3677 DEFER_GETTEXT ("software termination signum"), /* 15 SIGTERM */
|
|
3678 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
|
|
3679 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
|
|
3680 DEFER_GETTEXT ("death of a child"), /* 18 SIGCLD */
|
|
3681 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
|
|
3682 #ifdef sun
|
|
3683 DEFER_GETTEXT ("window size changed"), /* 20 SIGWINCH */
|
|
3684 DEFER_GETTEXT ("urgent socket condition"), /* 21 SIGURG */
|
|
3685 DEFER_GETTEXT ("pollable event occurred"), /* 22 SIGPOLL */
|
|
3686 DEFER_GETTEXT ("stop (cannot be caught or ignored)"), /* 23 SIGSTOP */
|
|
3687 DEFER_GETTEXT ("user stop requested from tty"), /* 24 SIGTSTP */
|
|
3688 DEFER_GETTEXT ("stopped process has been continued"), /* 25 SIGCONT */
|
|
3689 DEFER_GETTEXT ("background tty read attempted"), /* 26 SIGTTIN */
|
|
3690 DEFER_GETTEXT ("background tty write attempted"), /* 27 SIGTTOU */
|
|
3691 DEFER_GETTEXT ("virtual timer expired"), /* 28 SIGVTALRM */
|
|
3692 DEFER_GETTEXT ("profiling timer expired"), /* 29 SIGPROF */
|
|
3693 DEFER_GETTEXT ("exceeded cpu limit"), /* 30 SIGXCPU */
|
|
3694 DEFER_GETTEXT ("exceeded file size limit"), /* 31 SIGXFSZ */
|
|
3695 DEFER_GETTEXT ("process's lwps are blocked"), /* 32 SIGWAITING */
|
|
3696 DEFER_GETTEXT ("special signal used by thread library"), /* 33 SIGLWP */
|
|
3697 #ifdef SIGFREEZE
|
|
3698 DEFER_GETTEXT ("special signal used by CPR"), /* 34 SIGFREEZE */
|
|
3699 #endif
|
|
3700 #ifdef SIGTHAW
|
|
3701 DEFER_GETTEXT ("special signal used by CPR"), /* 35 SIGTHAW */
|
|
3702 #endif
|
|
3703 #endif /* sun */
|
|
3704 0
|
|
3705 };
|
|
3706 #endif /* not AIX */
|
|
3707 #endif /* USG */
|
|
3708 #ifdef DGUX
|
442
|
3709 const char *sys_siglist[NSIG + 1] =
|
428
|
3710 {
|
|
3711 DEFER_GETTEXT ("null signal"), /* 0 SIGNULL */
|
|
3712 DEFER_GETTEXT ("hangup"), /* 1 SIGHUP */
|
|
3713 DEFER_GETTEXT ("interrupt"), /* 2 SIGINT */
|
|
3714 DEFER_GETTEXT ("quit"), /* 3 SIGQUIT */
|
|
3715 DEFER_GETTEXT ("illegal instruction"), /* 4 SIGILL */
|
|
3716 DEFER_GETTEXT ("trace trap"), /* 5 SIGTRAP */
|
|
3717 DEFER_GETTEXT ("abort termination"), /* 6 SIGABRT */
|
|
3718 DEFER_GETTEXT ("SIGEMT"), /* 7 SIGEMT */
|
|
3719 DEFER_GETTEXT ("floating point exception"), /* 8 SIGFPE */
|
|
3720 DEFER_GETTEXT ("kill"), /* 9 SIGKILL */
|
|
3721 DEFER_GETTEXT ("bus error"), /* 10 SIGBUS */
|
|
3722 DEFER_GETTEXT ("segmentation violation"), /* 11 SIGSEGV */
|
|
3723 DEFER_GETTEXT ("bad argument to system call"), /* 12 SIGSYS */
|
|
3724 DEFER_GETTEXT ("write on a pipe with no reader"), /* 13 SIGPIPE */
|
|
3725 DEFER_GETTEXT ("alarm clock"), /* 14 SIGALRM */
|
|
3726 DEFER_GETTEXT ("software termination signal"), /* 15 SIGTERM */
|
|
3727 DEFER_GETTEXT ("user defined signal 1"), /* 16 SIGUSR1 */
|
|
3728 DEFER_GETTEXT ("user defined signal 2"), /* 17 SIGUSR2 */
|
|
3729 DEFER_GETTEXT ("child stopped or terminated"), /* 18 SIGCLD */
|
|
3730 DEFER_GETTEXT ("power-fail restart"), /* 19 SIGPWR */
|
|
3731 DEFER_GETTEXT ("window size changed"), /* 20 SIGWINCH */
|
|
3732 DEFER_GETTEXT ("undefined"), /* 21 */
|
|
3733 DEFER_GETTEXT ("pollable event occurred"), /* 22 SIGPOLL */
|
|
3734 DEFER_GETTEXT ("sendable stop signal not from tty"), /* 23 SIGSTOP */
|
|
3735 DEFER_GETTEXT ("stop signal from tty"), /* 24 SIGSTP */
|
|
3736 DEFER_GETTEXT ("continue a stopped process"), /* 25 SIGCONT */
|
|
3737 DEFER_GETTEXT ("attempted background tty read"), /* 26 SIGTTIN */
|
|
3738 DEFER_GETTEXT ("attempted background tty write"), /* 27 SIGTTOU */
|
|
3739 DEFER_GETTEXT ("undefined"), /* 28 */
|
|
3740 DEFER_GETTEXT ("undefined"), /* 29 */
|
|
3741 DEFER_GETTEXT ("undefined"), /* 30 */
|
|
3742 DEFER_GETTEXT ("undefined"), /* 31 */
|
|
3743 DEFER_GETTEXT ("undefined"), /* 32 */
|
|
3744 DEFER_GETTEXT ("socket (TCP/IP) urgent data arrival"), /* 33 SIGURG */
|
|
3745 DEFER_GETTEXT ("I/O is possible"), /* 34 SIGIO */
|
|
3746 DEFER_GETTEXT ("exceeded cpu time limit"), /* 35 SIGXCPU */
|
|
3747 DEFER_GETTEXT ("exceeded file size limit"), /* 36 SIGXFSZ */
|
|
3748 DEFER_GETTEXT ("virtual time alarm"), /* 37 SIGVTALRM */
|
|
3749 DEFER_GETTEXT ("profiling time alarm"), /* 38 SIGPROF */
|
|
3750 DEFER_GETTEXT ("undefined"), /* 39 */
|
|
3751 DEFER_GETTEXT ("file record locks revoked"), /* 40 SIGLOST */
|
|
3752 DEFER_GETTEXT ("undefined"), /* 41 */
|
|
3753 DEFER_GETTEXT ("undefined"), /* 42 */
|
|
3754 DEFER_GETTEXT ("undefined"), /* 43 */
|
|
3755 DEFER_GETTEXT ("undefined"), /* 44 */
|
|
3756 DEFER_GETTEXT ("undefined"), /* 45 */
|
|
3757 DEFER_GETTEXT ("undefined"), /* 46 */
|
|
3758 DEFER_GETTEXT ("undefined"), /* 47 */
|
|
3759 DEFER_GETTEXT ("undefined"), /* 48 */
|
|
3760 DEFER_GETTEXT ("undefined"), /* 49 */
|
|
3761 DEFER_GETTEXT ("undefined"), /* 50 */
|
|
3762 DEFER_GETTEXT ("undefined"), /* 51 */
|
|
3763 DEFER_GETTEXT ("undefined"), /* 52 */
|
|
3764 DEFER_GETTEXT ("undefined"), /* 53 */
|
|
3765 DEFER_GETTEXT ("undefined"), /* 54 */
|
|
3766 DEFER_GETTEXT ("undefined"), /* 55 */
|
|
3767 DEFER_GETTEXT ("undefined"), /* 56 */
|
|
3768 DEFER_GETTEXT ("undefined"), /* 57 */
|
|
3769 DEFER_GETTEXT ("undefined"), /* 58 */
|
|
3770 DEFER_GETTEXT ("undefined"), /* 59 */
|
|
3771 DEFER_GETTEXT ("undefined"), /* 60 */
|
|
3772 DEFER_GETTEXT ("undefined"), /* 61 */
|
|
3773 DEFER_GETTEXT ("undefined"), /* 62 */
|
|
3774 DEFER_GETTEXT ("undefined"), /* 63 */
|
|
3775 DEFER_GETTEXT ("notification message in mess. queue"), /* 64 SIGDGNOTIFY */
|
|
3776 0
|
|
3777 };
|
|
3778 #endif /* DGUX */
|
|
3779
|
|
3780 #endif /* ! SYS_SIGLIST_DECLARED && ! HAVE_SYS_SIGLIST */
|
|
3781
|
|
3782
|
|
3783 /************************************************************************/
|
|
3784 /* Directory routines for systems that don't have them */
|
|
3785 /************************************************************************/
|
|
3786
|
|
3787 #ifdef SYSV_SYSTEM_DIR
|
|
3788
|
|
3789 #include <dirent.h>
|
|
3790
|
|
3791 #if defined(BROKEN_CLOSEDIR) || !defined(HAVE_CLOSEDIR)
|
|
3792 int
|
|
3793 closedir (DIR *dirp) /* stream from opendir */
|
|
3794 {
|
|
3795 int rtnval;
|
|
3796
|
|
3797 rtnval = sys_close (dirp->dd_fd);
|
|
3798
|
|
3799 /* Some systems (like Solaris) allocate the buffer and the DIR all
|
|
3800 in one block. Why in the world are we freeing this ourselves
|
|
3801 anyway? */
|
|
3802 #if ! (defined (sun) && defined (USG5_4))
|
|
3803 xfree ((char *) dirp->dd_buf); /* directory block defined in <dirent.h> */
|
|
3804 #endif
|
|
3805 xfree ((char *) dirp);
|
|
3806 return (rtnval);
|
|
3807 }
|
|
3808 #endif /* BROKEN_CLOSEDIR or not HAVE_CLOSEDIR */
|
|
3809 #endif /* SYSV_SYSTEM_DIR */
|
|
3810
|
|
3811 #ifdef NONSYSTEM_DIR_LIBRARY
|
|
3812
|
|
3813 DIR *
|
442
|
3814 opendir (const char *filename) /* name of directory */
|
428
|
3815 {
|
|
3816 DIR *dirp; /* -> malloc'ed storage */
|
|
3817 int fd; /* file descriptor for read */
|
|
3818 struct stat sbuf; /* result of fstat */
|
|
3819
|
|
3820 fd = sys_open (filename, O_RDONLY);
|
|
3821 if (fd < 0)
|
|
3822 return 0;
|
|
3823
|
|
3824 if (fstat (fd, &sbuf) < 0
|
|
3825 || (sbuf.st_mode & S_IFMT) != S_IFDIR
|
|
3826 || (dirp = (DIR *) malloc (sizeof (DIR))) == 0)
|
|
3827 {
|
|
3828 sys_close (fd);
|
|
3829 return 0; /* bad luck today */
|
|
3830 }
|
|
3831
|
|
3832 dirp->dd_fd = fd;
|
|
3833 dirp->dd_loc = dirp->dd_size = 0; /* refill needed */
|
|
3834
|
|
3835 return dirp;
|
|
3836 }
|
|
3837
|
|
3838 void
|
|
3839 closedir (DIR *dirp) /* stream from opendir */
|
|
3840 {
|
|
3841 sys_close (dirp->dd_fd);
|
|
3842 xfree (dirp);
|
|
3843 }
|
|
3844
|
|
3845
|
|
3846 #define DIRSIZ 14
|
|
3847 struct olddir
|
|
3848 {
|
|
3849 ino_t od_ino; /* inode */
|
|
3850 char od_name[DIRSIZ]; /* filename */
|
|
3851 };
|
|
3852
|
|
3853 static struct direct dir_static; /* simulated directory contents */
|
|
3854
|
|
3855 /* ARGUSED */
|
|
3856 struct direct *
|
|
3857 readdir (DIR *dirp) /* stream from opendir */
|
|
3858 {
|
|
3859 struct olddir *dp; /* -> directory data */
|
|
3860
|
|
3861 for (; ;)
|
|
3862 {
|
|
3863 if (dirp->dd_loc >= dirp->dd_size)
|
|
3864 dirp->dd_loc = dirp->dd_size = 0;
|
|
3865
|
|
3866 if (dirp->dd_size == 0 /* refill buffer */
|
|
3867 && (dirp->dd_size = sys_read (dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ)) <= 0)
|
|
3868 return 0;
|
|
3869
|
|
3870 dp = (struct olddir *) &dirp->dd_buf[dirp->dd_loc];
|
|
3871 dirp->dd_loc += sizeof (struct olddir);
|
|
3872
|
|
3873 if (dp->od_ino != 0) /* not deleted entry */
|
|
3874 {
|
|
3875 dir_static.d_ino = dp->od_ino;
|
|
3876 strncpy (dir_static.d_name, dp->od_name, DIRSIZ);
|
|
3877 dir_static.d_name[DIRSIZ] = '\0';
|
|
3878 dir_static.d_namlen = strlen (dir_static.d_name);
|
|
3879 dir_static.d_reclen = sizeof (struct direct)
|
|
3880 - MAXNAMLEN + 3
|
|
3881 + dir_static.d_namlen - dir_static.d_namlen % 4;
|
|
3882 return &dir_static; /* -> simulated structure */
|
|
3883 }
|
|
3884 }
|
|
3885 }
|
|
3886
|
|
3887
|
|
3888 #endif /* NONSYSTEM_DIR_LIBRARY */
|
|
3889
|
|
3890
|
|
3891 /* mkdir and rmdir functions, for systems which don't have them. */
|
|
3892
|
|
3893 #ifndef HAVE_MKDIR
|
|
3894 /*
|
|
3895 * Written by Robert Rother, Mariah Corporation, August 1985.
|
|
3896 *
|
|
3897 * If you want it, it's yours. All I ask in return is that if you
|
|
3898 * figure out how to do this in a Bourne Shell script you send me
|
|
3899 * a copy.
|
|
3900 * sdcsvax!rmr or rmr@uscd
|
|
3901 *
|
|
3902 * Severely hacked over by John Gilmore to make a 4.2BSD compatible
|
|
3903 * subroutine. 11Mar86; hoptoad!gnu
|
|
3904 *
|
|
3905 * Modified by rmtodd@uokmax 6-28-87 -- when making an already existing dir,
|
|
3906 * subroutine didn't return EEXIST. It does now.
|
|
3907 */
|
|
3908
|
|
3909 /*
|
|
3910 * Make a directory.
|
|
3911 */
|
|
3912 #ifdef MKDIR_PROTOTYPE
|
|
3913 MKDIR_PROTOTYPE
|
|
3914 #else
|
|
3915 int
|
442
|
3916 mkdir (const char *dpath, int dmode)
|
428
|
3917 #endif
|
|
3918 {
|
|
3919 int cpid, status, fd;
|
|
3920 struct stat statbuf;
|
|
3921
|
442
|
3922 if (stat (dpath, &statbuf) == 0) /* we do want stat() here */
|
428
|
3923 {
|
|
3924 errno = EEXIST; /* Stat worked, so it already exists */
|
|
3925 return -1;
|
|
3926 }
|
|
3927
|
|
3928 /* If stat fails for a reason other than non-existence, return error */
|
|
3929 if (errno != ENOENT)
|
|
3930 return -1;
|
|
3931
|
|
3932 synch_process_alive = 1;
|
|
3933 switch (cpid = fork ())
|
|
3934 {
|
|
3935
|
|
3936 case -1: /* Error in fork() */
|
|
3937 return -1; /* Errno is set already */
|
|
3938
|
|
3939 case 0: /* Child process */
|
|
3940 {
|
|
3941 /*
|
|
3942 * Cheap hack to set mode of new directory. Since this
|
|
3943 * child process is going away anyway, we zap its umask.
|
|
3944 * ####, this won't suffice to set SUID, SGID, etc. on this
|
|
3945 * directory. Does anybody care?
|
|
3946 */
|
|
3947 status = umask (0); /* Get current umask */
|
|
3948 status = umask (status | (0777 & ~dmode)); /* Set for mkdir */
|
|
3949 fd = sys_open ("/dev/null", O_RDWR);
|
|
3950 if (fd >= 0)
|
|
3951 {
|
|
3952 if (fd != STDIN_FILENO) dup2 (fd, STDIN_FILENO);
|
|
3953 if (fd != STDOUT_FILENO) dup2 (fd, STDOUT_FILENO);
|
|
3954 if (fd != STDERR_FILENO) dup2 (fd, STDERR_FILENO);
|
|
3955 }
|
|
3956 execl ("/bin/mkdir", "mkdir", dpath, (char *) 0);
|
|
3957 _exit (-1); /* Can't exec /bin/mkdir */
|
|
3958 }
|
|
3959
|
|
3960 default: /* Parent process */
|
|
3961 wait_for_termination (cpid);
|
|
3962 }
|
|
3963
|
|
3964 if (synch_process_death != 0 || synch_process_retcode != 0)
|
|
3965 {
|
|
3966 errno = EIO; /* We don't know why, but */
|
|
3967 return -1; /* /bin/mkdir failed */
|
|
3968 }
|
|
3969
|
|
3970 return 0;
|
|
3971 }
|
|
3972 #endif /* not HAVE_MKDIR */
|
|
3973
|
|
3974 #ifndef HAVE_RMDIR
|
|
3975 int
|
442
|
3976 rmdir (const char *dpath)
|
428
|
3977 {
|
|
3978 int cpid, status, fd;
|
|
3979 struct stat statbuf;
|
|
3980
|
442
|
3981 if (stat (dpath, &statbuf) != 0) /* we do want stat() here */
|
428
|
3982 {
|
|
3983 /* Stat just set errno. We don't have to */
|
|
3984 return -1;
|
|
3985 }
|
|
3986
|
|
3987 synch_process_alive = 1;
|
|
3988 switch (cpid = fork ())
|
|
3989 {
|
|
3990
|
|
3991 case -1: /* Error in fork() */
|
|
3992 return (-1); /* Errno is set already */
|
|
3993
|
|
3994 case 0: /* Child process */
|
|
3995 fd = sys_open("/dev/null", O_RDWR);
|
|
3996 if (fd >= 0)
|
|
3997 {
|
|
3998 if (fd != STDIN_FILENO) dup2 (fd, STDIN_FILENO);
|
|
3999 if (fd != STDOUT_FILENO) dup2 (fd, STDOUT_FILENO);
|
|
4000 if (fd != STDERR_FILENO) dup2 (fd, STDERR_FILENO);
|
|
4001 }
|
|
4002 execl ("/bin/rmdir", "rmdir", dpath, (char *) 0);
|
|
4003 _exit (-1); /* Can't exec /bin/mkdir */
|
|
4004
|
|
4005 default: /* Parent process */
|
|
4006 wait_for_termination (cpid);
|
|
4007 }
|
|
4008
|
|
4009 if (synch_process_death != 0 ||
|
|
4010 synch_process_retcode != 0)
|
|
4011 {
|
|
4012 errno = EIO; /* We don't know why, but */
|
|
4013 return -1; /* /bin/rmdir failed */
|
|
4014 }
|
|
4015
|
|
4016 return 0;
|
|
4017 }
|
|
4018 #endif /* !HAVE_RMDIR */
|
|
4019
|
|
4020
|
|
4021 /************************************************************************/
|
|
4022 /* Misc. SunOS crap */
|
|
4023 /************************************************************************/
|
|
4024
|
|
4025 #ifdef USE_DL_STUBS
|
|
4026
|
|
4027 /* These are included on Sunos 4.1 when we do not use shared libraries.
|
|
4028 X11 libraries may refer to these functions but (we hope) do not
|
|
4029 actually call them. */
|
|
4030
|
|
4031 void *
|
|
4032 dlopen (void)
|
|
4033 {
|
|
4034 return 0;
|
|
4035 }
|
|
4036
|
|
4037 void *
|
|
4038 dlsym (void)
|
|
4039 {
|
|
4040 return 0;
|
|
4041 }
|
|
4042
|
|
4043 int
|
|
4044 dlclose (void)
|
|
4045 {
|
|
4046 return -1;
|
|
4047 }
|
|
4048
|
|
4049 #endif /* USE_DL_STUBS */
|