diff options
| author | Richard M. Stallman | 1993-05-13 00:21:47 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-05-13 00:21:47 +0000 |
| commit | cd9565badbbfdbdb91f98ab015048ea3c80987fb (patch) | |
| tree | cb6ed857246549829529a3cbca35bcf39be441d1 /src/callproc.c | |
| parent | 1a40d27fa251a6e805355d7f73093155b8e33057 (diff) | |
| download | emacs-cd9565badbbfdbdb91f98ab015048ea3c80987fb.tar.gz emacs-cd9565badbbfdbdb91f98ab015048ea3c80987fb.zip | |
(child_setup): Omit duplicates from new env array.
Diffstat (limited to 'src/callproc.c')
| -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) | |||
| 463 | tem = XCONS (tem)->cdr) | 463 | tem = XCONS (tem)->cdr) |
| 464 | new_length++; | 464 | new_length++; |
| 465 | 465 | ||
| 466 | /* new_length + 1 to include terminating 0 */ | 466 | /* new_length + 1 to include terminating 0. */ |
| 467 | env = new_env = (char **) alloca ((new_length + 1) * sizeof (char *)); | 467 | env = new_env = (char **) alloca ((new_length + 1) * sizeof (char *)); |
| 468 | 468 | ||
| 469 | /* Copy the Vprocess_alist strings into new_env. */ | 469 | /* Copy the Vprocess_environment strings into new_env. */ |
| 470 | for (tem = Vprocess_environment; | 470 | for (tem = Vprocess_environment; |
| 471 | (XTYPE (tem) == Lisp_Cons | 471 | (XTYPE (tem) == Lisp_Cons |
| 472 | && XTYPE (XCONS (tem)->car) == Lisp_String); | 472 | && XTYPE (XCONS (tem)->car) == Lisp_String); |
| 473 | tem = XCONS (tem)->cdr) | 473 | tem = XCONS (tem)->cdr) |
| 474 | *new_env++ = (char *) XSTRING (XCONS (tem)->car)->data; | 474 | { |
| 475 | char **ep = env; | ||
| 476 | char *string = (char *) XSTRING (XCONS (tem)->car)->data; | ||
| 477 | /* See if this string duplicates any string already in the env. | ||
| 478 | If so, don't put it in. | ||
| 479 | When an env var has multiple definitions, | ||
| 480 | we keep the definition that comes first in process-environment. */ | ||
| 481 | for (; ep != new_env; ep++) | ||
| 482 | { | ||
| 483 | char *p = *ep, *q = string; | ||
| 484 | while (1) | ||
| 485 | { | ||
| 486 | if (*q == 0) | ||
| 487 | /* The string is malformed; might as well drop it. */ | ||
| 488 | goto duplicate; | ||
| 489 | if (*q != *p) | ||
| 490 | break; | ||
| 491 | if (*q == '=') | ||
| 492 | goto duplicate; | ||
| 493 | p++, q++; | ||
| 494 | } | ||
| 495 | } | ||
| 496 | *new_env++ = string; | ||
| 497 | duplicate: ; | ||
| 498 | } | ||
| 475 | *new_env = 0; | 499 | *new_env = 0; |
| 476 | } | 500 | } |
| 477 | 501 | ||