brian       98/05/28 16:14:12

  Modified:    src/main util_script.c
  Log:
  PR: 2294
  Submitted by: W G Stoddard <[EMAIL PROTECTED]>
  Reviewed by:  Brian Behlendorf
  
  The environment variables were not properly being passed to the spawned
  process, now they are.
  
  Revision  Changes    Path
  1.114     +37 -11    apache-1.3/src/main/util_script.c
  
  Index: util_script.c
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/main/util_script.c,v
  retrieving revision 1.113
  retrieving revision 1.114
  diff -u -r1.113 -r1.114
  --- util_script.c     1998/05/28 11:32:44     1.113
  +++ util_script.c     1998/05/28 23:14:11     1.114
  @@ -711,7 +711,9 @@
        int is_exe = 0;
        STARTUPINFO si;
        PROCESS_INFORMATION pi;
  -     char *pCommand;
  +        char *pCommand;
  +        char *pEnvBlock, *pNext;
  +        int iEnvBlockLen;
   
        memset(&si, 0, sizeof(si));
        memset(&pi, 0, sizeof(pi));
  @@ -861,16 +863,40 @@
                                      r->filename, " ", arguments, NULL);
            }
        }
  -     
  -     if (CreateProcess(NULL, pCommand, NULL, NULL, TRUE, 0, env, NULL, &si, 
&pi)) {
  -       pid = pi.dwProcessId;
  -       /*
  -        * We must close the handles to the new process and its main thread
  -        * to prevent handle and memory leaks.
  -        */ 
  -       CloseHandle(pi.hProcess);
  -       CloseHandle(pi.hThread);
  -     }
  +  
  +        /*
  +         * Win32's CreateProcess call requires that the environment
  +         * be passed in an environment block, a null terminated block of
  +         * null terminated strings.
  +         */
  +  
  +        i = 0;
  +        iEnvBlockLen = 1;
  +        while (env[i]) {
  +            iEnvBlockLen += strlen(env[i]) + 1;
  +            i++;
  +        }
  +  
  +        pEnvBlock = (char *)ap_pcalloc(r->pool,iEnvBlockLen);
  +    
  +        i = 0;
  +        pNext = pEnvBlock;
  +        while (env[i]) {
  +            strcpy(pNext, env[i]);
  +            pNext = pNext + strlen(pNext) + 1;
  +            i++;
  +        }
  +
  +        if (CreateProcess(NULL, pCommand, NULL, NULL, TRUE, 0, pEnvBlock,
  +                          NULL, &si, &pi)) {
  +            pid = pi.dwProcessId;
  +            /*
  +             * We must close the handles to the new process and its main 
thread
  +             * to prevent handle and memory leaks.
  +             */ 
  +            CloseHandle(pi.hProcess);
  +            CloseHandle(pi.hThread);
  +        }
   #if 0
        if ((!r->args) || (!r->args[0]) || strchr(r->args, '=')) {
            if (is_exe || is_binary) {
  
  
  

Reply via email to