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