diff options
| author | Jim Blandy | 1993-03-20 21:53:57 +0000 |
|---|---|---|
| committer | Jim Blandy | 1993-03-20 21:53:57 +0000 |
| commit | 426b37aecf593645d44344ca7feace662ea3360d (patch) | |
| tree | e6e432dbe37e75e3943e0d3e0aeb887163543db9 /src/callproc.c | |
| parent | a4fc73600689c581d66df71f2fae14f97fe42649 (diff) | |
| download | emacs-426b37aecf593645d44344ca7feace662ea3360d.tar.gz emacs-426b37aecf593645d44344ca7feace662ea3360d.zip | |
* callproc.c (child_setup): Make sure that in, out, and err are
not less than three.
(relocate_fd): New function.
Diffstat (limited to 'src/callproc.c')
| -rw-r--r-- | src/callproc.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/callproc.c b/src/callproc.c index 383a1d74774..4b674eb9946 100644 --- a/src/callproc.c +++ b/src/callproc.c | |||
| @@ -23,6 +23,11 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |||
| 23 | 23 | ||
| 24 | #include "config.h" | 24 | #include "config.h" |
| 25 | 25 | ||
| 26 | extern int errno; | ||
| 27 | #ifndef VMS | ||
| 28 | extern char *sys_errlist[]; | ||
| 29 | #endif | ||
| 30 | |||
| 26 | /* Define SIGCHLD as an alias for SIGCLD. */ | 31 | /* Define SIGCHLD as an alias for SIGCLD. */ |
| 27 | 32 | ||
| 28 | #if !defined (SIGCHLD) && defined (SIGCLD) | 33 | #if !defined (SIGCHLD) && defined (SIGCLD) |
| @@ -474,6 +479,14 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir) | |||
| 474 | *new_env = 0; | 479 | *new_env = 0; |
| 475 | } | 480 | } |
| 476 | 481 | ||
| 482 | /* Make sure that in, out, and err are not actually already in | ||
| 483 | descriptors zero, one, or two; this could happen if Emacs is | ||
| 484 | started with its standard in, our, or error closed, as might | ||
| 485 | happen under X. */ | ||
| 486 | in = relocate_fd (in, 3); | ||
| 487 | out = relocate_fd (out, 3); | ||
| 488 | err = relocate_fd (err, 3); | ||
| 489 | |||
| 477 | close (0); | 490 | close (0); |
| 478 | close (1); | 491 | close (1); |
| 479 | close (2); | 492 | close (2); |
| @@ -507,6 +520,35 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir) | |||
| 507 | _exit (1); | 520 | _exit (1); |
| 508 | } | 521 | } |
| 509 | 522 | ||
| 523 | /* Move the file descriptor FD so that its number is not less than MIN. | ||
| 524 | If the file descriptor is moved at all, the original is freed. */ | ||
| 525 | int | ||
| 526 | relocate_fd (fd, min) | ||
| 527 | int fd, min; | ||
| 528 | { | ||
| 529 | if (fd >= min) | ||
| 530 | return fd; | ||
| 531 | else | ||
| 532 | { | ||
| 533 | int new = dup (fd); | ||
| 534 | if (new == -1) | ||
| 535 | { | ||
| 536 | char message1[] = | ||
| 537 | "Error while setting up child: "; | ||
| 538 | char message2[] = "\n"; | ||
| 539 | write (2, message1, sizeof (message1) - 1); | ||
| 540 | write (2, sys_errlist[errno], strlen (sys_errlist[errno])); | ||
| 541 | write (2, message2, sizeof (message2) - 1); | ||
| 542 | _exit (1); | ||
| 543 | } | ||
| 544 | /* Note that we hold the original FD open while we recurse, | ||
| 545 | to guarantee we'll get a new FD if we need it. */ | ||
| 546 | new = relocate_fd (new, min); | ||
| 547 | close (fd); | ||
| 548 | return new; | ||
| 549 | } | ||
| 550 | } | ||
| 551 | |||
| 510 | static int | 552 | static int |
| 511 | getenv_internal (var, varlen, value, valuelen) | 553 | getenv_internal (var, varlen, value, valuelen) |
| 512 | char *var; | 554 | char *var; |