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