comparison src/callproc.c @ 2286:7f66b40a0192

* callproc.c (child_setup): Make sure that in, out, and err are not less than three. (relocate_fd): New function.
author Jim Blandy <jimb@redhat.com>
date Sat, 20 Mar 1993 21:53:57 +0000
parents f0d4fb2b9157
children 17a84e60603b
comparison
equal deleted inserted replaced
2285:f0a979beceab 2286:7f66b40a0192
20 20
21 #include <signal.h> 21 #include <signal.h>
22 #include <errno.h> 22 #include <errno.h>
23 23
24 #include "config.h" 24 #include "config.h"
25
26 extern int errno;
27 #ifndef VMS
28 extern char *sys_errlist[];
29 #endif
25 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)
29 #define SIGCHLD SIGCLD 34 #define SIGCHLD SIGCLD
472 tem = XCONS (tem)->cdr) 477 tem = XCONS (tem)->cdr)
473 *new_env++ = (char *) XSTRING (XCONS (tem)->car)->data; 478 *new_env++ = (char *) XSTRING (XCONS (tem)->car)->data;
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);
480 493
481 dup2 (in, 0); 494 dup2 (in, 0);
503 execvp (new_argv[0], new_argv); 516 execvp (new_argv[0], new_argv);
504 517
505 write (1, "Couldn't exec the program ", 26); 518 write (1, "Couldn't exec the program ", 26);
506 write (1, new_argv[0], strlen (new_argv[0])); 519 write (1, new_argv[0], strlen (new_argv[0]));
507 _exit (1); 520 _exit (1);
521 }
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 }
508 } 550 }
509 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;