comparison src/callproc.c @ 7722:e422f06592d3

(child_setup): If PWD is set, set it in the child so that it points at the child's working directory.
author Richard M. Stallman <rms@gnu.org>
date Sat, 28 May 1994 08:29:36 +0000
parents b7d23c08750c
children 5fc8a3a9539a
comparison
equal deleted inserted replaced
7721:b04897534717 7722:e422f06592d3
569 #ifdef MSDOS 569 #ifdef MSDOS
570 /* The MSDOS port of gcc cannot fork, vfork, ... so we must call system 570 /* The MSDOS port of gcc cannot fork, vfork, ... so we must call system
571 instead. */ 571 instead. */
572 #else /* not MSDOS */ 572 #else /* not MSDOS */
573 char **env; 573 char **env;
574 char *pwd_var;
574 575
575 int pid = getpid (); 576 int pid = getpid ();
576 577
577 #ifdef SET_EMACS_PRIORITY 578 #ifdef SET_EMACS_PRIORITY
578 { 579 {
593 that do not have true vfork or that have true (stack) alloca. 594 that do not have true vfork or that have true (stack) alloca.
594 If using vfork and C_ALLOCA it is safe because that changes 595 If using vfork and C_ALLOCA it is safe because that changes
595 the superior's static variables as if the superior had done alloca 596 the superior's static variables as if the superior had done alloca
596 and will be cleaned up in the usual way. */ 597 and will be cleaned up in the usual way. */
597 { 598 {
598 register unsigned char *temp; 599 register char *temp;
599 register int i; 600 register int i;
600 601
601 i = XSTRING (current_dir)->size; 602 i = XSTRING (current_dir)->size;
602 temp = (unsigned char *) alloca (i + 2); 603 pwd_var = (char *) alloca (i + 6);
604 temp = pwd_var + 4;
605 bcopy ("PWD=", pwd_var, 4);
603 bcopy (XSTRING (current_dir)->data, temp, i); 606 bcopy (XSTRING (current_dir)->data, temp, i);
604 if (temp[i - 1] != '/') temp[i++] = '/'; 607 if (temp[i - 1] != '/') temp[i++] = '/';
605 temp[i] = 0; 608 temp[i] = 0;
606 609
607 /* We can't signal an Elisp error here; we're in a vfork. Since 610 /* We can't signal an Elisp error here; we're in a vfork. Since
609 should only return an error if the directory's permissions 612 should only return an error if the directory's permissions
610 are changed between the check and this chdir, but we should 613 are changed between the check and this chdir, but we should
611 at least check. */ 614 at least check. */
612 if (chdir (temp) < 0) 615 if (chdir (temp) < 0)
613 exit (errno); 616 exit (errno);
617
618 /* Strip trailing slashes for PWD, but leave "/" and "//" alone. */
619 while (i > 2 && temp[i - 1] == '/')
620 temp[--i] = 0;
614 } 621 }
615 622
616 /* Set `env' to a vector of the strings in Vprocess_environment. */ 623 /* Set `env' to a vector of the strings in Vprocess_environment. */
617 { 624 {
618 register Lisp_Object tem; 625 register Lisp_Object tem;
624 (XTYPE (tem) == Lisp_Cons 631 (XTYPE (tem) == Lisp_Cons
625 && XTYPE (XCONS (tem)->car) == Lisp_String); 632 && XTYPE (XCONS (tem)->car) == Lisp_String);
626 tem = XCONS (tem)->cdr) 633 tem = XCONS (tem)->cdr)
627 new_length++; 634 new_length++;
628 635
629 /* new_length + 1 to include terminating 0. */ 636 /* new_length + 2 to include PWD and terminating 0. */
630 env = new_env = (char **) alloca ((new_length + 1) * sizeof (char *)); 637 env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *));
638
639 /* If we have a PWD envvar, pass one down,
640 but with corrected value. */
641 if (getenv ("PWD"))
642 *new_env++ = pwd_var;
631 643
632 /* Copy the Vprocess_environment strings into new_env. */ 644 /* Copy the Vprocess_environment strings into new_env. */
633 for (tem = Vprocess_environment; 645 for (tem = Vprocess_environment;
634 (XTYPE (tem) == Lisp_Cons 646 (XTYPE (tem) == Lisp_Cons
635 && XTYPE (XCONS (tem)->car) == Lisp_String); 647 && XTYPE (XCONS (tem)->car) == Lisp_String);