Fix network build

This commit is contained in:
Andy Cedilnik 2002-10-10 11:08:52 -04:00
parent fe100ef263
commit 5b9feb6fdc
1 changed files with 181 additions and 179 deletions

View File

@ -279,12 +279,12 @@ bool cmWin32ProcessExecution::Wait(int timeout)
static void *_PyPopenProcs = NULL; static void *_PyPopenProcs = NULL;
static BOOL RealPopenCreateProcess(const char *cmdstring, static BOOL RealPopenCreateProcess(const char *cmdstring,
const char *path, const char *path,
const char *szConsoleSpawn, const char *szConsoleSpawn,
HANDLE hStdin, HANDLE hStdin,
HANDLE hStdout, HANDLE hStdout,
HANDLE hStderr, HANDLE hStderr,
HANDLE *hProcess) HANDLE *hProcess)
{ {
PROCESS_INFORMATION piProcInfo; PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo; STARTUPINFO siStartInfo;
@ -310,13 +310,14 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
++comshell; ++comshell;
if (GetVersion() < 0x80000000 && if (GetVersion() < 0x80000000 &&
STRICMP(comshell, "command.com") != 0) STRICMP(comshell, "command.com") != 0)
{ {
/* NT/2000 and not using command.com. */ /* NT/2000 and not using command.com. */
x = i + (int)strlen(s3) + (int)strlen(cmdstring) + 1; x = i + (int)strlen(s3) + (int)strlen(cmdstring) + 1;
s2 = (char *)_alloca(x); s2 = (char *)_alloca(x);
ZeroMemory(s2, x); ZeroMemory(s2, x);
sprintf(s2, "%s%s%s", s1, s3, cmdstring); //sprintf(s2, "%s%s%s", s1, s3, cmdstring);
sprintf(s2, "%s", cmdstring);
} }
else else
{ {
@ -328,62 +329,62 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
struct stat statinfo; struct stat statinfo;
GetModuleFileName(NULL, modulepath, sizeof(modulepath)); GetModuleFileName(NULL, modulepath, sizeof(modulepath));
for (i = x = 0; modulepath[i]; i++) for (i = x = 0; modulepath[i]; i++)
if (modulepath[i] == '\\') if (modulepath[i] == '\\')
x = i+1; x = i+1;
modulepath[x] = '\0'; modulepath[x] = '\0';
/* Create the full-name to w9xpopen, so we can test it exists */ /* Create the full-name to w9xpopen, so we can test it exists */
strncat(modulepath, strncat(modulepath,
szConsoleSpawn, szConsoleSpawn,
(sizeof(modulepath)/sizeof(modulepath[0])) (sizeof(modulepath)/sizeof(modulepath[0]))
-strlen(modulepath)); -strlen(modulepath));
if (stat(modulepath, &statinfo) != 0) if (stat(modulepath, &statinfo) != 0)
{ {
/* Eeek - file-not-found - possibly an embedding /* Eeek - file-not-found - possibly an embedding
situation - see if we can locate it in sys.prefix situation - see if we can locate it in sys.prefix
*/ */
strncpy(modulepath, strncpy(modulepath,
".", ".",
sizeof(modulepath)/sizeof(modulepath[0])); sizeof(modulepath)/sizeof(modulepath[0]));
if (modulepath[strlen(modulepath)-1] != '\\') if (modulepath[strlen(modulepath)-1] != '\\')
strcat(modulepath, "\\"); strcat(modulepath, "\\");
strncat(modulepath, strncat(modulepath,
szConsoleSpawn, szConsoleSpawn,
(sizeof(modulepath)/sizeof(modulepath[0])) (sizeof(modulepath)/sizeof(modulepath[0]))
-strlen(modulepath)); -strlen(modulepath));
/* No where else to look - raise an easily identifiable /* No where else to look - raise an easily identifiable
error, rather than leaving Windows to report error, rather than leaving Windows to report
"file not found" - as the user is probably blissfully "file not found" - as the user is probably blissfully
unaware this shim EXE is used, and it will confuse them. unaware this shim EXE is used, and it will confuse them.
(well, it confused me for a while ;-) (well, it confused me for a while ;-)
*/ */
if (stat(modulepath, &statinfo) != 0) if (stat(modulepath, &statinfo) != 0)
{ {
std::cout std::cout
<< "Can not locate '" << modulepath << "Can not locate '" << modulepath
<< "' which is needed " << "' which is needed "
"for popen to work with your shell " "for popen to work with your shell "
"or platform." << std::endl; "or platform." << std::endl;
return FALSE; return FALSE;
} }
} }
x = i + (int)strlen(s3) + (int)strlen(cmdstring) + 1 + x = i + (int)strlen(s3) + (int)strlen(cmdstring) + 1 +
(int)strlen(modulepath) + (int)strlen(modulepath) +
(int)strlen(szConsoleSpawn) + 1; (int)strlen(szConsoleSpawn) + 1;
s2 = (char *)_alloca(x); s2 = (char *)_alloca(x);
ZeroMemory(s2, x); ZeroMemory(s2, x);
sprintf( sprintf(
s2, s2,
"%s %s%s%s", "%s %s%s%s",
modulepath, modulepath,
s1, s1,
s3, s3,
cmdstring); cmdstring);
sprintf( sprintf(
s2, s2,
"%s %s", "%s %s",
modulepath, modulepath,
cmdstring); cmdstring);
} }
} }
@ -392,7 +393,7 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
else else
{ {
std::cout << "Cannot locate a COMSPEC environment variable to " std::cout << "Cannot locate a COMSPEC environment variable to "
<< "use as the shell" << std::endl; << "use as the shell" << std::endl;
return FALSE; return FALSE;
} }
@ -404,16 +405,17 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
siStartInfo.hStdError = hStderr; siStartInfo.hStdError = hStderr;
siStartInfo.wShowWindow = SW_HIDE; siStartInfo.wShowWindow = SW_HIDE;
//std::cout << "Create process: " << s2 << std::endl;
if (CreateProcess(NULL, if (CreateProcess(NULL,
s2, s2,
NULL, NULL,
NULL, NULL,
TRUE, TRUE,
CREATE_NEW_CONSOLE, CREATE_NEW_CONSOLE,
NULL, NULL,
path, path,
&siStartInfo, &siStartInfo,
&piProcInfo) ) &piProcInfo) )
{ {
/* Close the handles now so anyone waiting is woken. */ /* Close the handles now so anyone waiting is woken. */
CloseHandle(piProcInfo.hThread); CloseHandle(piProcInfo.hThread);
@ -429,9 +431,9 @@ static BOOL RealPopenCreateProcess(const char *cmdstring,
/* The following code is based off of KB: Q190351 */ /* The following code is based off of KB: Q190351 */
bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring, bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring,
const char* path, const char* path,
int mode, int mode,
int n) int n)
{ {
HANDLE hChildStdinRd, hChildStdinWr, hChildStdoutRd, hChildStdoutWr, HANDLE hChildStdinRd, hChildStdinWr, hChildStdoutRd, hChildStdoutWr,
hChildStderrRd, hChildStderrWr, hChildStdinWrDup, hChildStdoutRdDup, hChildStderrRd, hChildStderrWr, hChildStdinWrDup, hChildStdoutRdDup,
@ -456,9 +458,9 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring,
* the these handles; resulting in non-closeable handles to the pipes * the these handles; resulting in non-closeable handles to the pipes
* being created. */ * being created. */
fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr, fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr,
GetCurrentProcess(), &hChildStdinWrDup, 0, GetCurrentProcess(), &hChildStdinWrDup, 0,
FALSE, FALSE,
DUPLICATE_SAME_ACCESS); DUPLICATE_SAME_ACCESS);
if (!fSuccess) if (!fSuccess)
return win32_error("DuplicateHandle", NULL); return win32_error("DuplicateHandle", NULL);
@ -471,8 +473,8 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring,
return win32_error("CreatePipe", NULL); return win32_error("CreatePipe", NULL);
fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd, fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd,
GetCurrentProcess(), &hChildStdoutRdDup, 0, GetCurrentProcess(), &hChildStdoutRdDup, 0,
FALSE, DUPLICATE_SAME_ACCESS); FALSE, DUPLICATE_SAME_ACCESS);
if (!fSuccess) if (!fSuccess)
return win32_error("DuplicateHandle", NULL); return win32_error("DuplicateHandle", NULL);
@ -485,10 +487,10 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring,
if (!CreatePipe(&hChildStderrRd, &hChildStderrWr, &saAttr, 0)) if (!CreatePipe(&hChildStderrRd, &hChildStderrWr, &saAttr, 0))
return win32_error("CreatePipe", NULL); return win32_error("CreatePipe", NULL);
fSuccess = DuplicateHandle(GetCurrentProcess(), fSuccess = DuplicateHandle(GetCurrentProcess(),
hChildStderrRd, hChildStderrRd,
GetCurrentProcess(), GetCurrentProcess(),
&hChildStderrRdDup, 0, &hChildStderrRdDup, 0,
FALSE, DUPLICATE_SAME_ACCESS); FALSE, DUPLICATE_SAME_ACCESS);
if (!fSuccess) if (!fSuccess)
return win32_error("DuplicateHandle", NULL); return win32_error("DuplicateHandle", NULL);
/* Close the inheritable version of ChildStdErr that we're using. */ /* Close the inheritable version of ChildStdErr that we're using. */
@ -500,132 +502,132 @@ bool cmWin32ProcessExecution::PrivateOpen(const char *cmdstring,
{ {
case POPEN_1: case POPEN_1:
switch (mode & (_O_RDONLY | _O_TEXT | _O_BINARY | _O_WRONLY)) switch (mode & (_O_RDONLY | _O_TEXT | _O_BINARY | _O_WRONLY))
{ {
case _O_WRONLY | _O_TEXT: case _O_WRONLY | _O_TEXT:
/* Case for writing to child Stdin in text mode. */ /* Case for writing to child Stdin in text mode. */
fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode); fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode);
//f1 = _fdopen(fd1, "w"); //f1 = _fdopen(fd1, "w");
/* We don't care about these pipes anymore, /* We don't care about these pipes anymore,
so close them. */ so close them. */
CloseHandle(hChildStdoutRdDup); CloseHandle(hChildStdoutRdDup);
CloseHandle(hChildStderrRdDup); CloseHandle(hChildStderrRdDup);
break; break;
case _O_RDONLY | _O_TEXT: case _O_RDONLY | _O_TEXT:
/* Case for reading from child Stdout in text mode. */ /* Case for reading from child Stdout in text mode. */
fd1 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode); fd1 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode);
//f1 = _fdopen(fd1, "r"); //f1 = _fdopen(fd1, "r");
/* We don't care about these pipes anymore, /* We don't care about these pipes anymore,
so close them. */ so close them. */
CloseHandle(hChildStdinWrDup); CloseHandle(hChildStdinWrDup);
CloseHandle(hChildStderrRdDup); CloseHandle(hChildStderrRdDup);
break; break;
case _O_RDONLY | _O_BINARY: case _O_RDONLY | _O_BINARY:
/* Case for readinig from child Stdout in /* Case for readinig from child Stdout in
binary mode. */ binary mode. */
fd1 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode); fd1 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode);
//f1 = _fdopen(fd1, "rb"); //f1 = _fdopen(fd1, "rb");
/* We don't care about these pipes anymore, /* We don't care about these pipes anymore,
so close them. */ so close them. */
CloseHandle(hChildStdinWrDup); CloseHandle(hChildStdinWrDup);
CloseHandle(hChildStderrRdDup); CloseHandle(hChildStderrRdDup);
break; break;
case _O_WRONLY | _O_BINARY: case _O_WRONLY | _O_BINARY:
/* Case for writing to child Stdin in binary mode. */ /* Case for writing to child Stdin in binary mode. */
fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode); fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode);
//f1 = _fdopen(fd1, "wb"); //f1 = _fdopen(fd1, "wb");
/* We don't care about these pipes anymore, /* We don't care about these pipes anymore,
so close them. */ so close them. */
CloseHandle(hChildStdoutRdDup); CloseHandle(hChildStdoutRdDup);
CloseHandle(hChildStderrRdDup); CloseHandle(hChildStderrRdDup);
break; break;
} }
break; break;
case POPEN_2: case POPEN_2:
case POPEN_4: case POPEN_4:
if ( 1 ) if ( 1 )
{ {
// Comment this out. Maybe we will need it in the future. // Comment this out. Maybe we will need it in the future.
// file IO access to the process might be cool. // file IO access to the process might be cool.
//char *m1, *m2; //char *m1, *m2;
//if (mode && _O_TEXT) //if (mode && _O_TEXT)
// { // {
// m1 = "r"; // m1 = "r";
// m2 = "w"; // m2 = "w";
// } // }
//else //else
// { // {
// m1 = "rb"; // m1 = "rb";
// m2 = "wb"; // m2 = "wb";
// } // }
fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode); fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode);
//f1 = _fdopen(fd1, m2); //f1 = _fdopen(fd1, m2);
fd2 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode); fd2 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode);
//f2 = _fdopen(fd2, m1); //f2 = _fdopen(fd2, m1);
if (n != 4) if (n != 4)
{ {
CloseHandle(hChildStderrRdDup); CloseHandle(hChildStderrRdDup);
} }
break; break;
} }
case POPEN_3: case POPEN_3:
if ( 1) if ( 1)
{ {
// Comment this out. Maybe we will need it in the future. // Comment this out. Maybe we will need it in the future.
// file IO access to the process might be cool. // file IO access to the process might be cool.
//char *m1, *m2; //char *m1, *m2;
//if (mode && _O_TEXT) //if (mode && _O_TEXT)
// { // {
// m1 = "r"; // m1 = "r";
// m2 = "w"; // m2 = "w";
// } // }
//else //else
// { // {
// m1 = "rb"; // m1 = "rb";
// m2 = "wb"; // m2 = "wb";
// } // }
fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode); fd1 = _open_osfhandle(TO_INTPTR(hChildStdinWrDup), mode);
//f1 = _fdopen(fd1, m2); //f1 = _fdopen(fd1, m2);
fd2 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode); fd2 = _open_osfhandle(TO_INTPTR(hChildStdoutRdDup), mode);
//f2 = _fdopen(fd2, m1); //f2 = _fdopen(fd2, m1);
fd3 = _open_osfhandle(TO_INTPTR(hChildStderrRdDup), mode); fd3 = _open_osfhandle(TO_INTPTR(hChildStderrRdDup), mode);
//f3 = _fdopen(fd3, m1); //f3 = _fdopen(fd3, m1);
break; break;
} }
} }
if (n == POPEN_4) if (n == POPEN_4)
{ {
if (!RealPopenCreateProcess(cmdstring, if (!RealPopenCreateProcess(cmdstring,
path, path,
this->m_ConsoleSpawn.c_str(), this->m_ConsoleSpawn.c_str(),
hChildStdinRd, hChildStdinRd,
hChildStdoutWr, hChildStdoutWr,
hChildStdoutWr, hChildStdoutWr,
&hProcess)) &hProcess))
return NULL; return NULL;
} }
else else
{ {
if (!RealPopenCreateProcess(cmdstring, if (!RealPopenCreateProcess(cmdstring,
path, path,
this->m_ConsoleSpawn.c_str(), this->m_ConsoleSpawn.c_str(),
hChildStdinRd, hChildStdinRd,
hChildStdoutWr, hChildStdoutWr,
hChildStderrWr, hChildStderrWr,
&hProcess)) &hProcess))
return NULL; return NULL;
} }
@ -740,9 +742,9 @@ bool cmWin32ProcessExecution::PrivateClose(int /* timeout */)
int len = read(this->m_pStdErr, buffer, 1023); int len = read(this->m_pStdErr, buffer, 1023);
buffer[len] = 0; buffer[len] = 0;
if ( this->m_Verbose ) if ( this->m_Verbose )
{ {
std::cout << buffer << std::flush; std::cout << buffer << std::flush;
} }
output += buffer; output += buffer;
have_some = true; have_some = true;
} }
@ -752,9 +754,9 @@ bool cmWin32ProcessExecution::PrivateClose(int /* timeout */)
int len = read(this->m_pStdOut, buffer, 1023); int len = read(this->m_pStdOut, buffer, 1023);
buffer[len] = 0; buffer[len] = 0;
if ( this->m_Verbose ) if ( this->m_Verbose )
{ {
std::cout << buffer << std::flush; std::cout << buffer << std::flush;
} }
output += buffer; output += buffer;
have_some = true; have_some = true;
} }