diff options
| author | Richard M. Stallman | 1994-05-28 08:29:36 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-05-28 08:29:36 +0000 |
| commit | 7fcf7f051866dbe7fa831076583d92e5904d4450 (patch) | |
| tree | 54d6fbd7ae48dcdb36f75847cb78648b6d5bac7e /src | |
| parent | 32b50df655cbf91c5d089dfdd40a0f269d04f34e (diff) | |
| download | emacs-7fcf7f051866dbe7fa831076583d92e5904d4450.tar.gz emacs-7fcf7f051866dbe7fa831076583d92e5904d4450.zip | |
(child_setup): If PWD is set, set it in the child so that
it points at the child's working directory.
Diffstat (limited to 'src')
| -rw-r--r-- | src/callproc.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/callproc.c b/src/callproc.c index cdf8f1a67c0..12c4485b4a5 100644 --- a/src/callproc.c +++ b/src/callproc.c | |||
| @@ -571,6 +571,7 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir) | |||
| 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 | ||
| @@ -595,11 +596,13 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir) | |||
| 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; |
| @@ -611,6 +614,10 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir) | |||
| 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. */ |
| @@ -626,8 +633,13 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir) | |||
| 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; |