diff options
| author | Richard M. Stallman <rms@gnu.org> | 1993-05-13 00:21:47 +0000 |
|---|---|---|
| committer | Richard M. Stallman <rms@gnu.org> | 1993-05-13 00:21:47 +0000 |
| commit | cd9565badbbfdbdb91f98ab015048ea3c80987fb (patch) | |
| tree | cb6ed857246549829529a3cbca35bcf39be441d1 | |
| parent | 1a40d27fa251a6e805355d7f73093155b8e33057 (diff) | |
| download | emacs-cd9565badbbfdbdb91f98ab015048ea3c80987fb.tar.gz | |
(child_setup): Omit duplicates from new env array.
| -rw-r--r-- | src/callproc.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/callproc.c b/src/callproc.c index 7fd218b584d..df5405a07fc 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -463,15 +463,39 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir) tem = XCONS (tem)->cdr) new_length++; - /* new_length + 1 to include terminating 0 */ + /* new_length + 1 to include terminating 0. */ env = new_env = (char **) alloca ((new_length + 1) * sizeof (char *)); - /* Copy the Vprocess_alist strings into new_env. */ + /* Copy the Vprocess_environment strings into new_env. */ for (tem = Vprocess_environment; (XTYPE (tem) == Lisp_Cons && XTYPE (XCONS (tem)->car) == Lisp_String); tem = XCONS (tem)->cdr) - *new_env++ = (char *) XSTRING (XCONS (tem)->car)->data; + { + char **ep = env; + char *string = (char *) XSTRING (XCONS (tem)->car)->data; + /* See if this string duplicates any string already in the env. + If so, don't put it in. + When an env var has multiple definitions, + we keep the definition that comes first in process-environment. */ + for (; ep != new_env; ep++) + { + char *p = *ep, *q = string; + while (1) + { + if (*q == 0) + /* The string is malformed; might as well drop it. */ + goto duplicate; + if (*q != *p) + break; + if (*q == '=') + goto duplicate; + p++, q++; + } + } + *new_env++ = string; + duplicate: ; + } *new_env = 0; } |
