From: Hartmut Birr Date: Mon, 1 Apr 2002 21:58:45 +0000 (+0000) Subject: Removed fixed size of args and envblock in go32_exec() (gcc uses a very large cmd... X-Git-Tag: backups/mpw@12443~139 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=3005268105be67bb837df06074cdeef8791076fd Removed fixed size of args and envblock in go32_exec() (gcc uses a very large cmd line). Added closing of thread and/or process handle at exit in _spawnve(). Added debug messages. svn path=/trunk/; revision=2803 --- diff --git a/reactos/lib/msvcrt/process/spawnve.c b/reactos/lib/msvcrt/process/spawnve.c index 1f44421d9d2..ef57d96092d 100644 --- a/reactos/lib/msvcrt/process/spawnve.c +++ b/reactos/lib/msvcrt/process/spawnve.c @@ -13,6 +13,9 @@ #include #include +#define NDEBUG +#include + #ifndef F_OK #define F_OK 0x01 @@ -35,7 +38,7 @@ int _fileinfo_dll = 0; static int direct_exec_tail(const char *program, const char *args, - char * const envp[], + const char * envp, PROCESS_INFORMATION *ProcessInformation) { @@ -43,13 +46,16 @@ direct_exec_tail(const char *program, const char *args, StartupInfo.cb = sizeof(STARTUPINFO); StartupInfo.lpReserved= NULL; - StartupInfo.dwFlags = 0; + StartupInfo.dwFlags = 0 /*STARTF_USESTDHANDLES*/; StartupInfo.wShowWindow = SW_SHOWDEFAULT; StartupInfo.lpReserved2 = NULL; StartupInfo.cbReserved2 = 0; + StartupInfo.hStdInput = _get_osfhandle(0); + StartupInfo.hStdOutput = _get_osfhandle(1); + StartupInfo.hStdError = _get_osfhandle(2); - if (! CreateProcessA((char *)program,(char *)args,NULL,NULL,FALSE,0,(char **)envp,NULL,&StartupInfo,ProcessInformation) ) + if (! CreateProcessA((char *)program,(char *)args,NULL,NULL,TRUE,0,(LPVOID)envp,NULL,&StartupInfo,ProcessInformation) ) { __set_errno( GetLastError() ); return -1; @@ -78,33 +84,45 @@ static int vdm_exec(const char *program, char **argv, char **envp, static int go32_exec(const char *program, char **argv, char **envp, PROCESS_INFORMATION *ProcessInformation) { + char * penvblock, * ptr; + char * args; + int i, len, result; + for (i = 0, len = 0; envp[i]; i++) { + len += strlen(envp[i]) + 1; + } + penvblock = ptr = (char*)malloc(len + 1); + if (penvblock == NULL) + return -1; - static char args[1024]; - static char envblock[2048]; - char * penvblock; - int i = 0; - - - envblock[0] = 0; - penvblock=envblock; + for(i = 0, *ptr = 0; envp[i]; i++) { + strcpy(ptr, envp[i]); + ptr += strlen(envp[i]) + 1; + } + *ptr = 0; - while(envp[i] != NULL ) { - strcat(penvblock,envp[i]); - penvblock+=strlen(envp[i])+1; - i++; + for(i = 0, len = 0; argv[i]; i++) { + len += strlen(argv[i]) + 1; + } + + args = (char*) malloc(len + 1); + if (args == NULL) + { + free(penvblock); + return -1; } - penvblock[0]=0; - args[0] = 0; - i = 0; - while(argv[i] != NULL ) { + for(i = 0, *args = 0; argv[i]; i++) { strcat(args,argv[i]); - strcat(args," "); - i++; + if (argv[i+1] != NULL) { + strcat(args," "); + } } - return direct_exec_tail(program,args,envp,ProcessInformation); + result = direct_exec_tail(program,args,(const char*)penvblock,ProcessInformation); + free(args); + free(penvblock); + return result; } int @@ -183,14 +201,18 @@ int _spawnve(int mode, const char *path, char *const argv[], char *const envp[]) int found = 0; DWORD ExitCode; + DPRINT("_spawnve('%s')\n", path); + if (path == 0 || argv[0] == 0) { errno = EINVAL; + DPRINT("??\n"); return -1; } if (strlen(path) > FILENAME_MAX - 1) { errno = ENAMETOOLONG; + DPRINT("??\n"); return -1; } @@ -248,6 +270,7 @@ int _spawnve(int mode, const char *path, char *const argv[], char *const envp[]) } if (!found) { + DPRINT("??\n"); errno = is_dir ? EISDIR : ENOENT; return -1; } @@ -260,6 +283,12 @@ int _spawnve(int mode, const char *path, char *const argv[], char *const envp[]) WaitForSingleObject(ProcessInformation.hProcess,INFINITE); GetExitCodeProcess(ProcessInformation.hProcess,&ExitCode); i = (int)ExitCode; + CloseHandle(ProcessInformation.hThread); + CloseHandle(ProcessInformation.hProcess); + } + else + { + CloseHandle(ProcessInformation.hThread); } return i; }