Skip to content

Commit

Permalink
Inherit handles only if necessary on Windows
Browse files Browse the repository at this point in the history
Refs #2779 <#2779>
  • Loading branch information
rom1v committed Nov 14, 2021
1 parent 66f3398 commit 7fef713
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/src/sys/win/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ sc_process_execute_p(const char *const argv[], HANDLE *handle,
HANDLE *pin, HANDLE *pout, HANDLE *perr) {
enum sc_process_result ret = SC_PROCESS_ERROR_GENERIC;

bool inherit_handles = pin || pout || perr;

SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
Expand Down Expand Up @@ -69,7 +71,7 @@ sc_process_execute_p(const char *const argv[], HANDLE *handle,
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
if (pin || pout || perr) {
if (inherit_handles) {
si.dwFlags = STARTF_USESTDHANDLES;
if (pin) {
si.hStdInput = stdin_read_handle;
Expand All @@ -95,8 +97,8 @@ sc_process_execute_p(const char *const argv[], HANDLE *handle,
goto error_close_stderr;
}

if (!CreateProcessW(NULL, wide, NULL, NULL, TRUE, 0, NULL, NULL, &si,
&pi)) {
if (!CreateProcessW(NULL, wide, NULL, NULL, inherit_handles, 0, NULL, NULL,
&si, &pi)) {
free(wide);
*handle = NULL;

Expand Down

0 comments on commit 7fef713

Please sign in to comment.