diff options
| author | Geoff Voelker | 1997-01-04 22:26:26 +0000 |
|---|---|---|
| committer | Geoff Voelker | 1997-01-04 22:26:26 +0000 |
| commit | d9709fde351393361e1d8379aa7edea1a195b53c (patch) | |
| tree | ebe42de224855ffb669f0ef798d265ba310d86dd /src | |
| parent | 84d3f6e87870ed7eb646658a2d963675900d6bad (diff) | |
| download | emacs-d9709fde351393361e1d8379aa7edea1a195b53c.tar.gz emacs-d9709fde351393361e1d8379aa7edea1a195b53c.zip | |
(compare_env, merge_and_sort_env): New functions.
(sys_spawnve): Sort environment variables for subprocess.
(ppid_env_var_buffer): Variable deleted.
Diffstat (limited to 'src')
| -rw-r--r-- | src/w32proc.c | 66 |
1 files changed, 58 insertions, 8 deletions
diff --git a/src/w32proc.c b/src/w32proc.c index b8ada136cd3..755336299b4 100644 --- a/src/w32proc.c +++ b/src/w32proc.c | |||
| @@ -577,9 +577,49 @@ w32_is_dos_binary (char * filename) | |||
| 577 | return is_dos_binary; | 577 | return is_dos_binary; |
| 578 | } | 578 | } |
| 579 | 579 | ||
| 580 | /* We pass our process ID to our children by setting up an environment | 580 | int |
| 581 | variable in their environment. */ | 581 | compare_env (const char **strp1, const char **strp2) |
| 582 | char ppid_env_var_buffer[64]; | 582 | { |
| 583 | const char *str1 = *strp1, *str2 = *strp2; | ||
| 584 | |||
| 585 | while (*str1 && *str2 && *str1 != '=' && *str2 != '=') | ||
| 586 | { | ||
| 587 | if (tolower (*str1) > tolower (*str2)) | ||
| 588 | return 1; | ||
| 589 | else if (tolower (*str1) < tolower (*str2)) | ||
| 590 | return -1; | ||
| 591 | str1++, str2++; | ||
| 592 | } | ||
| 593 | |||
| 594 | if (*str1 == '=' && *str2 == '=') | ||
| 595 | return 0; | ||
| 596 | else if (*str1 == '=') | ||
| 597 | return -1; | ||
| 598 | else | ||
| 599 | return 1; | ||
| 600 | } | ||
| 601 | |||
| 602 | void | ||
| 603 | merge_and_sort_env (char **envp1, char **envp2, char **new_envp) | ||
| 604 | { | ||
| 605 | char **optr, **nptr; | ||
| 606 | int num; | ||
| 607 | |||
| 608 | nptr = new_envp; | ||
| 609 | optr = envp1; | ||
| 610 | while (*optr) | ||
| 611 | *nptr++ = *optr++; | ||
| 612 | num = optr - envp1; | ||
| 613 | |||
| 614 | optr = envp2; | ||
| 615 | while (*optr) | ||
| 616 | *nptr++ = *optr++; | ||
| 617 | num += optr - envp2; | ||
| 618 | |||
| 619 | qsort (new_envp, num, sizeof (char *), compare_env); | ||
| 620 | |||
| 621 | *nptr = NULL; | ||
| 622 | } | ||
| 583 | 623 | ||
| 584 | /* When a new child process is created we need to register it in our list, | 624 | /* When a new child process is created we need to register it in our list, |
| 585 | so intercept spawn requests. */ | 625 | so intercept spawn requests. */ |
| @@ -588,11 +628,15 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp) | |||
| 588 | { | 628 | { |
| 589 | Lisp_Object program, full; | 629 | Lisp_Object program, full; |
| 590 | char *cmdline, *env, *parg, **targ; | 630 | char *cmdline, *env, *parg, **targ; |
| 591 | int arglen; | 631 | int arglen, numenv; |
| 592 | int pid; | 632 | int pid; |
| 593 | child_process *cp; | 633 | child_process *cp; |
| 594 | int is_dos_binary; | 634 | int is_dos_binary; |
| 595 | 635 | /* We pass our process ID to our children by setting up an environment | |
| 636 | variable in their environment. */ | ||
| 637 | char ppid_env_var_buffer[64]; | ||
| 638 | char *extra_env[] = {ppid_env_var_buffer, NULL}; | ||
| 639 | |||
| 596 | /* We don't care about the other modes */ | 640 | /* We don't care about the other modes */ |
| 597 | if (mode != _P_NOWAIT) | 641 | if (mode != _P_NOWAIT) |
| 598 | { | 642 | { |
| @@ -726,16 +770,24 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp) | |||
| 726 | /* and envp... */ | 770 | /* and envp... */ |
| 727 | arglen = 1; | 771 | arglen = 1; |
| 728 | targ = envp; | 772 | targ = envp; |
| 773 | numenv = 1; /* for end null */ | ||
| 729 | while (*targ) | 774 | while (*targ) |
| 730 | { | 775 | { |
| 731 | arglen += strlen (*targ++) + 1; | 776 | arglen += strlen (*targ++) + 1; |
| 777 | numenv++; | ||
| 732 | } | 778 | } |
| 779 | /* extra env vars... */ | ||
| 733 | sprintf (ppid_env_var_buffer, "__PARENT_PROCESS_ID=%d", | 780 | sprintf (ppid_env_var_buffer, "__PARENT_PROCESS_ID=%d", |
| 734 | GetCurrentProcessId ()); | 781 | GetCurrentProcessId ()); |
| 735 | arglen += strlen (ppid_env_var_buffer) + 1; | 782 | arglen += strlen (ppid_env_var_buffer) + 1; |
| 783 | numenv++; | ||
| 736 | 784 | ||
| 785 | /* merge env passed in and extra env into one, and sort it. */ | ||
| 786 | targ = (char **) alloca (numenv * sizeof (char *)); | ||
| 787 | merge_and_sort_env (envp, extra_env, targ); | ||
| 788 | |||
| 789 | /* concatenate env entries. */ | ||
| 737 | env = alloca (arglen); | 790 | env = alloca (arglen); |
| 738 | targ = envp; | ||
| 739 | parg = env; | 791 | parg = env; |
| 740 | while (*targ) | 792 | while (*targ) |
| 741 | { | 793 | { |
| @@ -743,8 +795,6 @@ sys_spawnve (int mode, char *cmdname, char **argv, char **envp) | |||
| 743 | parg += strlen (*targ++); | 795 | parg += strlen (*targ++); |
| 744 | *parg++ = '\0'; | 796 | *parg++ = '\0'; |
| 745 | } | 797 | } |
| 746 | strcpy (parg, ppid_env_var_buffer); | ||
| 747 | parg += strlen (ppid_env_var_buffer); | ||
| 748 | *parg++ = '\0'; | 798 | *parg++ = '\0'; |
| 749 | *parg = '\0'; | 799 | *parg = '\0'; |
| 750 | 800 | ||