| 497 | */ |
| 498 | |
| 499 | static void invoke_cmd( char const * const command, int32_t const slot ) |
| 500 | { |
| 501 | SECURITY_ATTRIBUTES sa = { sizeof( SECURITY_ATTRIBUTES ), 0, 0 }; |
| 502 | SECURITY_DESCRIPTOR sd; |
| 503 | STARTUPINFOA si = { sizeof( STARTUPINFOA ), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 504 | 0, 0, 0, 0, 0, 0 }; |
| 505 | |
| 506 | /* Init the security data. */ |
| 507 | InitializeSecurityDescriptor( &sd, SECURITY_DESCRIPTOR_REVISION ); |
| 508 | SetSecurityDescriptorDacl( &sd, TRUE, NULL, FALSE ); |
| 509 | sa.lpSecurityDescriptor = &sd; |
| 510 | sa.bInheritHandle = TRUE; |
| 511 | |
| 512 | /* Create output buffers. */ |
| 513 | string_new( cmdtab[ slot ].buffer_out ); |
| 514 | string_new( cmdtab[ slot ].buffer_err ); |
| 515 | |
| 516 | /* Create pipes for communicating with the child process. */ |
| 517 | if ( !CreatePipe( &cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_READ ], |
| 518 | &cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_WRITE ], &sa, IO_BUFFER_SIZE ) ) |
| 519 | { |
| 520 | reportWindowsError( "CreatePipe", slot ); |
| 521 | return; |
| 522 | } |
| 523 | if ( globs.pipe_action && !CreatePipe( &cmdtab[ slot ].pipe_err[ |
| 524 | EXECCMD_PIPE_READ ], &cmdtab[ slot ].pipe_err[ EXECCMD_PIPE_WRITE ], |
| 525 | &sa, IO_BUFFER_SIZE ) ) |
| 526 | { |
| 527 | reportWindowsError( "CreatePipe", slot ); |
| 528 | return; |
| 529 | } |
| 530 | |
| 531 | /* Set handle inheritance off for the pipe ends the parent reads from. */ |
| 532 | SetHandleInformation( cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_READ ], |
| 533 | HANDLE_FLAG_INHERIT, 0 ); |
| 534 | if ( globs.pipe_action ) |
| 535 | SetHandleInformation( cmdtab[ slot ].pipe_err[ EXECCMD_PIPE_READ ], |
| 536 | HANDLE_FLAG_INHERIT, 0 ); |
| 537 | |
| 538 | /* Hide the child window, if any. */ |
| 539 | si.dwFlags |= STARTF_USESHOWWINDOW; |
| 540 | si.wShowWindow = SW_HIDE; |
| 541 | |
| 542 | /* Redirect the child's output streams to our pipes. */ |
| 543 | si.dwFlags |= STARTF_USESTDHANDLES; |
| 544 | si.hStdOutput = cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_WRITE ]; |
| 545 | si.hStdError = globs.pipe_action |
| 546 | ? cmdtab[ slot ].pipe_err[ EXECCMD_PIPE_WRITE ] |
| 547 | : cmdtab[ slot ].pipe_out[ EXECCMD_PIPE_WRITE ]; |
| 548 | |
| 549 | /* Let the child inherit stdin, as some commands assume it is available. */ |
| 550 | si.hStdInput = GetStdHandle( STD_INPUT_HANDLE ); |
| 551 | |
| 552 | if ( DEBUG_EXECCMD ) |
| 553 | out_printf( "Command string for CreateProcessA(): '%s'\n", command ); |
| 554 | |
| 555 | /* Run the command by creating a sub-process for it. */ |
| 556 | if ( !CreateProcessA( |
no test coverage detected