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