From abb13199ba156583bdb1a68f132c1052af6ff096 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 4 Jan 2005 14:57:42 +0000 Subject: [PATCH] * pinfo.cc (_pinfo::dup_proc_pipe): Can't close proc pipe when execing or we will suffer an exit code race. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/pinfo.cc | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 21f9f420d..9d0215c52 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2005-01-03 Christopher Faylor + + * pinfo.cc (_pinfo::dup_proc_pipe): Can't close proc pipe when execing + or we will suffer an exit code race. + 2005-01-03 Corinna Vinschen * signal.cc (abort): Call _GLOBAL_REENT's __cleanup. diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index d600b58bd..8ebc602e6 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -764,9 +764,14 @@ proc_waiter (void *arg) bool _pinfo::dup_proc_pipe (HANDLE hProcess) { + DWORD flags = DUPLICATE_SAME_ACCESS; + /* Grr. Can't set DUPLICATE_CLOSE_SOURCE for exec case because we could be + execing a non-cygwin process and we need to set the exit value before the + parent sees it. */ + if (this != myself) + flags |= DUPLICATE_CLOSE_SOURCE; bool res = DuplicateHandle (hMainProc, wr_proc_pipe, hProcess, &wr_proc_pipe, - 0, FALSE, - DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE); + 0, FALSE, flags); if (!res) sigproc_printf ("DuplicateHandle failed, pid %d, hProcess %p, %E", pid, hProcess); else