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