Ticket #441: proc_open.c.2.diff

File proc_open.c.2.diff, 1.0 kB (added by elvstone@…, 3 years ago)

Better to use %WINDIR%\system32\cmd.exe than to hardcode the path

  • src/proc_open.c

     
     1#include <string.h> 
    12#include <stdlib.h> 
    23#include <stdio.h> 
    34#include <ctype.h> 
     
    148149        STARTUPINFO si; 
    149150        BOOL procok; 
    150151        SECURITY_ATTRIBUTES security; 
    151         const char *shell; 
     152        char *shell; 
    152153        buffer *cmdline; 
    153154 
    154155        if (NULL == (shell = getenv(SHELLENV))) { 
    155                 fprintf(stderr, "env %s is required", SHELLENV); 
    156                 return -1; 
     156                if (NULL == (shell = getenv("WINDIR"))) { 
     157                        fprintf(stderr, "neither %s nor WINDIR in env, can't guess shell path\n", SHELLENV); 
     158                        return -1; 
     159                } 
     160                shell = strcat(shell, "\\system32\\cmd.exe"); 
    157161        } 
    158162 
    159163        /* we use this to allow the child to inherit handles */ 
     
    225229        pid_t child; 
    226230        const char *shell; 
    227231 
    228         if (NULL == (shell = getenv(SHELLENV))) { 
    229                 fprintf(stderr, "env %s is required", SHELLENV); 
    230                 return -1; 
    231         } 
     232        if (NULL == (shell = getenv(SHELLENV))) 
     233                shell = "/bin/sh"; 
    232234 
    233235        if (proc_open_pipes(proc) != 0) { 
    234236                return -1;