X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=pipex_win32.c;h=0bbf990282a9c1195ae5c63ec638efc93f995c9c;hb=471c4c42e267be298ce20951d5a352acd6b55190;hp=3f9ed90638b2087af8d83071f97ec9d3b906f6df;hpb=a0f731f21d6aa26dbf7246039a1c66c2ade0533f;p=polyglot.git diff --git a/pipex_win32.c b/pipex_win32.c index 3f9ed90..0bbf990 100644 --- a/pipex_win32.c +++ b/pipex_win32.c @@ -72,6 +72,8 @@ void pipex_open(pipex_t *pipex, char *szCurrentDir; pipex->state=0; pipex->name=szName; + pipex->command=szProcFile; + pipex->quit_pending=FALSE; pipex->hProcess=NULL; if (szProcFile == NULL) { pipex->hInput = GetStdHandle(STD_INPUT_HANDLE); @@ -92,14 +94,14 @@ void pipex_open(pipex_t *pipex, si.hStdInput = hStdinRead; si.hStdOutput = hStdoutWrite; si.hStdError = hStdoutWrite; - if((szCurrentDir = _getcwd( NULL, 0 )) == NULL ) + if((szCurrentDir = (char*)_getcwd( NULL, 0 )) == NULL ) my_fatal("pipex_open(): no current directory: %s\n", strerror(errno)); if(_chdir(szWorkingDir)){ my_fatal("pipex_open(): cannot change directory: %s\n", strerror(errno)); } - if(CreateProcess(NULL, + if(CreateProcess(NULL, (LPSTR) szProcFile, NULL, NULL, @@ -118,7 +120,7 @@ void pipex_open(pipex_t *pipex, pipex->bConsole = FALSE; pipex->bPipe=TRUE; }else{ - my_fatal("pipex_open(): %s",win32_error()); + my_fatal("pipex_open(): %s: %s",szProcFile,win32_error()); } _chdir(szCurrentDir); } @@ -191,10 +193,14 @@ void pipex_send_eof(pipex_t *pipex) { // pipex_exit() void pipex_exit(pipex_t *pipex) { + DWORD lpexit; CloseHandle(pipex->hInput); CloseHandle(pipex->hOutput); - DWORD lpexit; - + if(!pipex->quit_pending){ + // suppress further errors + pipex->quit_pending=TRUE; + my_fatal("pipex_exit(): %s: child exited unexpectedly.\n",pipex->command); + } if(GetExitCodeProcess(pipex->hProcess,&lpexit)){ if(lpexit==STILL_ACTIVE) //must be java,hammer it down! @@ -219,10 +225,7 @@ static void pipex_set_eof_input(pipex_t *pipex){ EnterCriticalSection(&(pipex->CriticalSection)); (pipex->state)|=PIPEX_EOF; LeaveCriticalSection(&(pipex->CriticalSection)); - // not quit the right place - my_log("%s->Adapter: EOF\n",pipex->name); - -} + } // pipex_active() @@ -395,6 +398,7 @@ bool pipex_readln(pipex_t *pipex, char *szLineStr) { WaitForSingleObject(pipex->hEvent,INFINITE); } } + my_log("%s->Adapter: EOF\n",pipex->name); szLineStr[0]='\0'; return FALSE; } @@ -431,12 +435,13 @@ void pipex_set_priority(pipex_t *pipex, int value){ // pipex_set_affinit() +typedef void (WINAPI *SPAM)(HANDLE, int); void pipex_set_affinity(pipex_t *pipex, int value){ + SPAM pSPAM; + if(pipex->hProcess) return; if(value==-1) return; - typedef void (WINAPI *SPAM)(HANDLE, int); - SPAM pSPAM; pSPAM = (SPAM) GetProcAddress( GetModuleHandle(TEXT("kernel32.dll")), "SetProcessAffinityMask"); @@ -474,8 +479,8 @@ void pipex_write(pipex_t *pipex, const char *szLineStr) { void pipex_writeln(pipex_t *pipex, const char *szLineStr) { DWORD dwBytes; DWORD dwLengthWriteBuffer; - my_log("Adapter->%s: %s\n",pipex->name,pipex->szWriteBuffer); pipex_write(pipex, szLineStr); + my_log("Adapter->%s: %s\n",pipex->name,pipex->szWriteBuffer); if(pipex->bPipe){ dwLengthWriteBuffer = strlen(pipex->szWriteBuffer); if(dwLengthWriteBuffer>=sizeof(pipex->szWriteBuffer)-3){