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