Skip to content

[windows] Procs Wait Fix#234

Open
Mr-Emacs wants to merge 1 commit intotsoding:mainfrom
Mr-Emacs:procshandle
Open

[windows] Procs Wait Fix#234
Mr-Emacs wants to merge 1 commit intotsoding:mainfrom
Mr-Emacs:procshandle

Conversation

@Mr-Emacs
Copy link
Copy Markdown

This is an issue to fix procs wait so child that is created will be inheritable from the child.

Previously:

The child process handle was not working properly

Z:\home\segfault\Programming\issex>nob.exe
[INFO] renaming nob.exe -> nob.exe.old
[INFO] CMD: cl.exe /Fe:nob.exe nob.c
[ERROR] could not wait on child process: Invalid handle.
[INFO] renaming nob.exe.old -> nob.exe

Z:\home\segfault\Programming\issex>Microsoft (R) C/C++ Optimizing Compiler Version 19.50.35729 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

nob.c
Microsoft (R) Incremental Linker Version 14.50.35729.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:nob.exe
nob.obj

Z:\home\segfault\Programming\issex>

But now after the fix.

Z:\home\segfault\Programming\issex>
Z:\home\segfault\Programming\issex>nob.exe
[INFO] renaming nob.exe -> nob.exe.old
[INFO] CMD: cl.exe /Fe:nob.exe nob.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.50.35729 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

nob.c
Microsoft (R) Incremental Linker Version 14.50.35729.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:nob.exe
nob.obj
[INFO] CMD: nob.exe
[INFO] CMD: cl /Zi /Isrc /std:c11 /TC /DEMACS_PRINT /Feissex.exe src/main.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.50.35729 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

main.c
src/main.c(482): warning C4090: 'function': different 'const' qualifiers
Microsoft (R) Incremental Linker Version 14.50.35729.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/debug
/out:issex.exe
main.obj

The solution is to make the child process inheritable.

if (fdin || fdout || fderr) {
        HANDLE hStdIn  = fdin  ? *fdin  : GetStdHandle(STD_INPUT_HANDLE);
        HANDLE hStdOut = fdout ? *fdout : GetStdHandle(STD_OUTPUT_HANDLE);
        HANDLE hStdErr = fderr ? *fderr : GetStdHandle(STD_ERROR_HANDLE);
        SetHandleInformation(hStdIn,  HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
        SetHandleInformation(hStdOut, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
        SetHandleInformation(hStdErr, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
        siStartInfo.hStdInput  = hStdIn;
        siStartInfo.hStdOutput = hStdOut;
        siStartInfo.hStdError  = hStdErr;
        siStartInfo.dwFlags   |= STARTF_USESTDHANDLES;
    }

Then later check the exit code of each process.

This is an issue to fix procs wait so child that is created will be
inheritable from the child.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant