| 355 | */ |
| 356 | |
| 357 | void exec_wait() |
| 358 | { |
| 359 | int i = -1; |
| 360 | int exit_reason; /* reason why a command completed */ |
| 361 | |
| 362 | /* Wait for a command to complete, while snarfing up any output. */ |
| 363 | while ( 1 ) |
| 364 | { |
| 365 | /* Check for a complete command, briefly. */ |
| 366 | i = try_wait( 500 ); |
| 367 | /* Read in the output of all running commands. */ |
| 368 | read_output(); |
| 369 | /* Close out pending debug style dialogs. */ |
| 370 | close_alerts(); |
| 371 | /* Process the completed command we found. */ |
| 372 | if ( i >= 0 ) { exit_reason = EXIT_OK; break; } |
| 373 | /* Check if a command ran out of time. */ |
| 374 | i = try_kill_one(); |
| 375 | if ( i >= 0 ) { exit_reason = EXIT_TIMEOUT; break; } |
| 376 | } |
| 377 | |
| 378 | /* We have a command... process it. */ |
| 379 | { |
| 380 | DWORD exit_code; |
| 381 | timing_info time; |
| 382 | int rstat; |
| 383 | |
| 384 | /* The time data for the command. */ |
| 385 | record_times( cmdtab[ i ].pi.hProcess, &time ); |
| 386 | |
| 387 | /* Removed the used temporary command file. */ |
| 388 | if ( cmdtab[ i ].command_file->size ) |
| 389 | unlink( cmdtab[ i ].command_file->value ); |
| 390 | |
| 391 | /* Find out the process exit code. */ |
| 392 | GetExitCodeProcess( cmdtab[ i ].pi.hProcess, &exit_code ); |
| 393 | |
| 394 | /* The dispossition of the command. */ |
| 395 | if ( interrupted() ) |
| 396 | rstat = EXEC_CMD_INTR; |
| 397 | else if ( exit_code ) |
| 398 | rstat = EXEC_CMD_FAIL; |
| 399 | else |
| 400 | rstat = EXEC_CMD_OK; |
| 401 | |
| 402 | /* Call the callback, may call back to jam rule land. */ |
| 403 | (*cmdtab[ i ].func)( cmdtab[ i ].closure, rstat, &time, |
| 404 | cmdtab[ i ].buffer_out->value, cmdtab[ i ].buffer_err->value, |
| 405 | exit_reason ); |
| 406 | |
| 407 | /* Clean up our child process tracking data. No need to clear the |
| 408 | * temporary command file name as it gets reused. |
| 409 | */ |
| 410 | closeWinHandle( &cmdtab[ i ].pi.hProcess ); |
| 411 | closeWinHandle( &cmdtab[ i ].pi.hThread ); |
| 412 | closeWinHandle( &cmdtab[ i ].pipe_out[ EXECCMD_PIPE_READ ] ); |
| 413 | closeWinHandle( &cmdtab[ i ].pipe_out[ EXECCMD_PIPE_WRITE ] ); |
| 414 | closeWinHandle( &cmdtab[ i ].pipe_err[ EXECCMD_PIPE_READ ] ); |
no test coverage detected