To: chicken-hackers@nongnu.org Subject: [PATCH] Windows: pass inheritable standard handles to CreateProcess Hi, C_process, in the C embedded in posixwin.scm, duplicates a shared standard handle with bInheritHandle = FALSE, then calls CreateProcessW with bInheritHandles = TRUE and STARTF_USESTDHANDLES. Those handles have to be inheritable. DUPLICATE_SAME_ACCESS copies the access mask only; it does not keep the inherit flag. The pipe path already sets HANDLE_FLAG_INHERIT on the child's end. The share path does not. Commit 2477220 (ticket 765) removed a later SetHandleInformation pass that tried to mark these duplicates inheritable, because Windows 7 rejects that on some parent handles. This patch does not restore that pass. DuplicateHandle itself is allowed to create the duplicate inheritable. When standard error is not a console, the nested call fails with ERROR_INVALID_HANDLE, which this runtime maps to EBADF. Scheme reports it as (process) cannot execute process, errno 9. A console handle often still works, so a direct csc looks fine and a program spawned with (process ...) -- stderr shared, not (process* ...) -- fails when it spawns the next process. I saw this as a static compiler whose (process "cc" ...) failed only under a piped parent. After the flag is TRUE, the same nested spawn succeeded on 12 consecutive runs. The 6.0.0 tarball also ships this function already translated into posixwin.c. The edit there is the same, and is included below so a release tree does not keep compiling the old copy. --- a/posixwin.scm +++ b/posixwin.scm @@ -386,10 +386,15 @@ { if (f_share_io[i]) { + /* bInheritHandle is independent of DUPLICATE_SAME_ACCESS. + STARTF_USESTDHANDLES needs an inheritable duplicate; + FALSE fails CreateProcess with ERROR_INVALID_HANDLE + when stderr is not a console. Not the SetHandleInformation + pass removed for ticket 765. */ success = DuplicateHandle( cur_process, standard_io_handles[i], cur_process, &child_io_handles[i], - 0, FALSE, DUPLICATE_SAME_ACCESS); + 0, TRUE, DUPLICATE_SAME_ACCESS); } else { --- a/posixwin.c +++ b/posixwin.c @@ -458,10 +458,15 @@ { if (f_share_io[i]) { + /* bInheritHandle is independent of DUPLICATE_SAME_ACCESS. + STARTF_USESTDHANDLES needs an inheritable duplicate; + FALSE fails CreateProcess with ERROR_INVALID_HANDLE + when stderr is not a console. Not the SetHandleInformation + pass removed for ticket 765. */ success = DuplicateHandle( cur_process, standard_io_handles[i], cur_process, &child_io_handles[i], - 0, FALSE, DUPLICATE_SAME_ACCESS); + 0, TRUE, DUPLICATE_SAME_ACCESS); } else {