apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr/threadproc/win32 proc.c
Date Thu, 21 Mar 2002 05:48:26 GMT
wrowe       02/03/20 21:48:26

  Modified:    threadproc/win32 proc.c
  Log:
    Fix several bugs in proc.c, especially around command.com which
    behaves differently than cmd.exe with respect to the /c command arg.
  
  Revision  Changes    Path
  1.68      +31 -8     apr/threadproc/win32/proc.c
  
  Index: proc.c
  ===================================================================
  RCS file: /home/cvs/apr/threadproc/win32/proc.c,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -r1.67 -r1.68
  --- proc.c	19 Mar 2002 17:54:00 -0000	1.67
  +++ proc.c	21 Mar 2002 05:48:26 -0000	1.68
  @@ -295,6 +295,7 @@
       char *pEnvBlock;
       PROCESS_INFORMATION pi;
       DWORD dwCreationFlags = 0;
  +    char *ch;
   
       new->in = attr->parent_in;
       new->err = attr->parent_err;
  @@ -336,7 +337,11 @@
   
       i = 1;
       while (args && args[i]) {
  -        if (strchr(args[i], ' '))
  +        for (ch = args[i]; *ch; ++ch) {
  +            if (apr_iswhite(*ch)) {
  +                break;
  +        }
  +        if (*ch)
               cmdline = apr_pstrcat(pool, cmdline, " \"", args[i], "\"", NULL);
           else
               cmdline = apr_pstrcat(pool, cmdline, " ", args[i], NULL);
  @@ -347,13 +352,31 @@
   
       if (attr->cmdtype == APR_SHELLCMD) {
           char *shellcmd = getenv("COMSPEC");
  -        if (!shellcmd)
  -            shellcmd = SHELL_PATH;
  -        if (shellcmd[0] == '"')
  -            progname = apr_pstrndup(pool, shellcmd + 1, strlen(shellcmd) - 1);
  -        else if (strchr(shellcmd, ' '))
  -            shellcmd = apr_pstrcat(pool, "\"", shellcmd, "\"", NULL);
  -        cmdline = apr_pstrcat(pool, shellcmd, " /C \"", cmdline, "\"", NULL);
  +        if (!shellcmd) {
  +            return APR_EINVAL;
  +        }
  +        if (shellcmd[0] == '"') {
  +            progname = apr_pstrndup(pool, shellcmd + 1, strlen(shellcmd) - 2);
  +        }
  +        else {
  +            progname = shellcmd;
  +            for (ch = shellcmd; *ch; ++ch) {
  +                if (apr_iswhite(*ch)) {
  +                    break;
  +            }
  +            if (*ch)
  +                shellcmd = apr_pstrcat(pool, "\"", shellcmd, "\"", NULL);
  +            }
  +        }
  +        /* Command.com does not support a quoted command, while cmd.exe demands one.
  +         */
  +        i = strlen(progname);
  +        if (i >= 11 && strcasecmp(progname + i - 11, "command.com") == 0) {
  +            cmdline = apr_pstrcat(pool, shellcmd, " /C ", cmdline, NULL);
  +        }
  +        else {
  +            cmdline = apr_pstrcat(pool, shellcmd, " /C \"", cmdline, "\"", NULL);
  +        }
       } 
       else {
           /* Win32 is _different_ than unix.  While unix will find the given
  
  
  

Mime
View raw message