| 428 | */ |
| 429 | |
| 430 | static void invoke_cmd( char const * const command, int const slot ) |
| 431 | { |
| 432 | SECURITY_ATTRIBUTES sa = { sizeof( SECURITY_ATTRIBUTES ), 0, 0 }; |
| 433 | SECURITY_DESCRIPTOR sd; |
| 434 | STARTUPINFO si = { sizeof( STARTUPINFO ), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 435 | 0, 0, 0, 0, 0, 0 }; |
| 436 | |
| 437 | /* Init the security data. */ |
| 438 | InitializeSecurityDescriptor( &sd, SECURITY_DESCRIPTOR_REVISION ); |
| 439 | SetSecurityDescriptorDacl( &sd, TRUE, NULL, FALSE ); |
| 440 | sa.lpSecurityDescriptor = &sd; |
| 441 | sa.bInheritHandle = TRUE; |
| 442 | |
| 443 | /* Create output buffers. */ |
| 444 | string_new( cmdtab[ slot ].buffer_out ); |
| 445 | string_new( cmdtab[ slot ].buffer_err ); |
| 446 | |
| 447 | /* Create pipes for communicating with the child process. */ |
| 448 | if ( !CreatePipe( &cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_READ ], |
| 449 | &cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_WRITE ], &sa, 0 ) ) |
| 450 | { |
| 451 | reportWindowsError( "CreatePipe", slot ); |
| 452 | return; |
| 453 | } |
| 454 | if ( globs.pipe_action && !CreatePipe( &cmdtab[ slot ].pipe_err[ |
| 455 | EXECCMD_PIPE_READ ], &cmdtab[ slot ].pipe_err[ EXECCMD_PIPE_WRITE ], |
| 456 | &sa, 0 ) ) |
| 457 | { |
| 458 | reportWindowsError( "CreatePipe", slot ); |
| 459 | return; |
| 460 | } |
| 461 | |
| 462 | /* Set handle inheritance off for the pipe ends the parent reads from. */ |
| 463 | SetHandleInformation( cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_READ ], |
| 464 | HANDLE_FLAG_INHERIT, 0 ); |
| 465 | if ( globs.pipe_action ) |
| 466 | SetHandleInformation( cmdtab[ slot ].pipe_err[ EXECCMD_PIPE_READ ], |
| 467 | HANDLE_FLAG_INHERIT, 0 ); |
| 468 | |
| 469 | /* Hide the child window, if any. */ |
| 470 | si.dwFlags |= STARTF_USESHOWWINDOW; |
| 471 | si.wShowWindow = SW_HIDE; |
| 472 | |
| 473 | /* Redirect the child's output streams to our pipes. */ |
| 474 | si.dwFlags |= STARTF_USESTDHANDLES; |
| 475 | si.hStdOutput = cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_WRITE ]; |
| 476 | si.hStdError = globs.pipe_action |
| 477 | ? cmdtab[ slot ].pipe_err[ EXECCMD_PIPE_WRITE ] |
| 478 | : cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_WRITE ]; |
| 479 | |
| 480 | /* Let the child inherit stdin, as some commands assume it is available. */ |
| 481 | si.hStdInput = GetStdHandle( STD_INPUT_HANDLE ); |
| 482 | |
| 483 | if ( DEBUG_EXECCMD ) |
| 484 | out_printf( "Command string for CreateProcessA(): '%s'\n", command ); |
| 485 | |
| 486 | /* Run the command by creating a sub-process for it. */ |
| 487 | if ( !CreateProcessA( |
no test coverage detected