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