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