From: Christopher S. Hull Date: Wed, 9 Jun 2004 16:58:57 +0000 (+0000) Subject: always have CreateChildProcess execute process command via $COMSPEC X-Git-Tag: Release-1.34.4~14 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e4e9f6943168e47789efb9282e6a0e666b4df40d;p=bacula%2Fbacula always have CreateChildProcess execute process command via $COMSPEC git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1405 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/win32/compat/compat.cpp b/bacula/src/win32/compat/compat.cpp index 89392cb728..4a954ab50d 100644 --- a/bacula/src/win32/compat/compat.cpp +++ b/bacula/src/win32/compat/compat.cpp @@ -815,20 +815,6 @@ getArgv0(const char *cmdline) return rval; } -/* - * Check to see if filename has the batch file extention. - */ -int -isBatchFile(const char *fname) -{ - const char *ext = strrchr(fname, '.'); - - if (ext) { - int rval = strncasecmp(ext, ".bat", 4); - return !rval; - } - return 0; -} /** * OK, so it would seem CreateProcess only handles true executables: @@ -871,55 +857,20 @@ CreateChildProcess(const char *cmdline, HANDLE in, HANDLE out, HANDLE err) siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE); // Create the child process. - char cmdLine[1024]; - char exeFile[1024]; - // retrive the first compont of the command line which should be the - // executable - const char *exeName = getArgv0(cmdline); - - if (isBatchFile(exeName)) { - const char *comspec = getenv("COMSPEC"); - if (comspec == NULL) // should never happen - return INVALID_HANDLE_VALUE; - - free((void *)exeName); - strcpy(exeFile, comspec); - strcpy(cmdLine, comspec); - strcat(cmdLine, " /c "); - strcat(cmdLine, cmdline); - } - else - { - // check to see if absolute path was passed to us already? - // allow for case when absolute path is in quotes "C:/...." - int driveCheck = exeName[0] == '"' ? 2 : 1; - if (exeName[driveCheck] != ':' - || (strchr(cmdline, '/') == NULL - && strchr(cmdline, '\\') == NULL)) - { - // only command name so perform search of PATH to find - char *file; - DWORD rval = SearchPath(NULL, - exeName, - ".exe", - sizeof(exeFile), - exeFile, - &file); - if (rval == 0) - return INVALID_HANDLE_VALUE; - if (rval > sizeof(exeFile)) - return INVALID_HANDLE_VALUE; - - } - else - cygwin_conv_to_win32_path(exeName, exeFile); - - // exeFile now has absolute path to program to execute. - free((void *)exeName); + char exeFile[256]; + + const char *comspec = getenv("COMSPEC"); + + if (comspec == NULL) // should never happen + return INVALID_HANDLE_VALUE; + + char *cmdLine = (char *)alloca(strlen(cmdline) + strlen(comspec) + 16); + + strcpy(exeFile, comspec); + strcpy(cmdLine, comspec); + strcat(cmdLine, " /c "); + strcat(cmdLine, cmdline); - // copy original command line to pass to create process - strcpy(cmdLine, cmdline); - } // try to execute program bFuncRetn = CreateProcess(exeFile, cmdLine, // command line