comparison src/callproc.c @ 386:4af0ddfb7c5b r21-2-8

Import from CVS: tag r21-2-8
author cvs
date Mon, 13 Aug 2007 11:08:50 +0200
parents bbff43aa5eb7
children 74fd4e045ea6
comparison
equal deleted inserted replaced
385:bc48d89bf15c 386:4af0ddfb7c5b
624 pwd[--i] = 0; 624 pwd[--i] = 0;
625 } 625 }
626 } 626 }
627 627
628 /* Set `env' to a vector of the strings in Vprocess_environment. */ 628 /* Set `env' to a vector of the strings in Vprocess_environment. */
629 /* + 2 to include PWD and terminating 0. */
630 env = alloca_array (char *, XINT (Flength (Vprocess_environment)) + 2);
629 { 631 {
630 REGISTER Lisp_Object tem; 632 REGISTER Lisp_Object tail;
631 REGISTER char **new_env; 633 char **new_env = env;
632 REGISTER int new_length = 0;
633
634 for (tem = Vprocess_environment;
635 (CONSP (tem)
636 && STRINGP (XCAR (tem)));
637 tem = XCDR (tem))
638 new_length++;
639
640 /* new_length + 2 to include PWD and terminating 0. */
641 env = new_env = alloca_array (char *, new_length + 2);
642 634
643 /* If we have a PWD envvar and we know the real current directory, 635 /* If we have a PWD envvar and we know the real current directory,
644 pass one down, but with corrected value. */ 636 pass one down, but with corrected value. */
645 if (pwd && getenv ("PWD")) 637 if (pwd && getenv ("PWD"))
646 *new_env++ = pwd; 638 *new_env++ = pwd;
647 639
648 /* Copy the Vprocess_environment strings into new_env. */ 640 /* Copy the Vprocess_environment strings into new_env. */
649 for (tem = Vprocess_environment; 641 for (tail = Vprocess_environment;
650 (CONSP (tem) 642 CONSP (tail) && STRINGP (XCAR (tail));
651 && STRINGP (XCAR (tem))); 643 tail = XCDR (tail))
652 tem = XCDR (tem))
653 { 644 {
654 char **ep = env; 645 char **ep = env;
655 char *string = (char *) XSTRING_DATA (XCAR (tem)); 646 char *envvar_external;
656 /* See if this string duplicates any string already in the env. 647 Bufbyte *envvar_internal = XSTRING_DATA (XCAR (tail));
648
649 GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA (envvar_internal, envvar_external);
650
651 /* See if envvar_external duplicates any string already in the env.
657 If so, don't put it in. 652 If so, don't put it in.
658 When an env var has multiple definitions, 653 When an env var has multiple definitions,
659 we keep the definition that comes first in process-environment. */ 654 we keep the definition that comes first in process-environment. */
660 for (; ep != new_env; ep++) 655 for (; ep != new_env; ep++)
661 { 656 {
662 char *p = *ep, *q = string; 657 char *p = *ep, *q = envvar_external;
663 while (1) 658 while (1)
664 { 659 {
665 if (*q == 0) 660 if (*q == 0)
666 /* The string is malformed; might as well drop it. */ 661 /* The string is malformed; might as well drop it. */
667 goto duplicate; 662 goto duplicate;
670 if (*q == '=') 665 if (*q == '=')
671 goto duplicate; 666 goto duplicate;
672 p++, q++; 667 p++, q++;
673 } 668 }
674 } 669 }
675 if (pwd && !strncmp ("PWD=", string, 4)) 670 if (pwd && !strncmp ("PWD=", envvar_external, 4))
676 { 671 {
677 *new_env++ = pwd; 672 *new_env++ = pwd;
678 pwd = 0; 673 pwd = 0;
679 } 674 }
680 else 675 else
681 *new_env++ = string; 676 *new_env++ = envvar_external;
677
682 duplicate: ; 678 duplicate: ;
683 } 679 }
684 *new_env = 0; 680 *new_env = 0;
685 } 681 }
682
686 #ifdef WINDOWSNT 683 #ifdef WINDOWSNT
687 prepare_standard_handles (in, out, err, handles); 684 prepare_standard_handles (in, out, err, handles);
688 set_process_dir (current_dir); 685 set_process_dir (current_dir);
689 #else /* not WINDOWSNT */ 686 #else /* not WINDOWSNT */
690 /* Make sure that in, out, and err are not actually already in 687 /* Make sure that in, out, and err are not actually already in
697 694
698 /* Set the standard input/output channels of the new process. */ 695 /* Set the standard input/output channels of the new process. */
699 close (STDIN_FILENO); 696 close (STDIN_FILENO);
700 close (STDOUT_FILENO); 697 close (STDOUT_FILENO);
701 close (STDERR_FILENO); 698 close (STDERR_FILENO);
702 699
703 dup2 (in, STDIN_FILENO); 700 dup2 (in, STDIN_FILENO);
704 dup2 (out, STDOUT_FILENO); 701 dup2 (out, STDOUT_FILENO);
705 dup2 (err, STDERR_FILENO); 702 dup2 (err, STDERR_FILENO);
706 703
707 close (in); 704 close (in);
708 close (out); 705 close (out);
709 close (err); 706 close (err);
710 707
711 /* I can't think of any reason why child processes need any more 708 /* I can't think of any reason why child processes need any more