From edf5a5bd1530a09f602227da243b94a88bc8b0b4 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 17 Oct 2008 16:24:20 +0000 Subject: [PATCH] * dtable.cc (dtable::get_debugger_info): Call SetStdHandle for the newly opened handle. Explain why. (dtable::stdio_init): Don't duplicate standard error handle when stderr has already been created under debugger control. --- winsup/cygwin/ChangeLog | 7 +++++++ winsup/cygwin/dtable.cc | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 0c3361fcf..444d6b702 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2008-10-17 Corinna Vinschen + + * dtable.cc (dtable::get_debugger_info): Call SetStdHandle + for the newly opened handle. Explain why. + (dtable::stdio_init): Don't duplicate standard error handle + when stderr has already been created under debugger control. + 2008-10-13 Corinna Vinschen * sec_acl.cc (setacl): Align standard owner and group permissions diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index cca215671..d8d7c2ba7 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -128,6 +128,11 @@ dtable::get_debugger_info () release (i); else CloseHandle (h); + /* Copy to Windows' idea of a standard handle, otherwise + we have invalid standard handles when calling Windows + functions (small_printf and strace might suffer, too). */ + SetStdHandle (std_consts[i], i ? fh->get_output_handle () + : fh->get_handle ()); } } } @@ -161,7 +166,11 @@ dtable::stdio_init () /* STD_ERROR_HANDLE has been observed to be the same as STD_OUTPUT_HANDLE. We need separate handles (e.g. using pipes to pass data from child to parent). */ - if (out == err) + /* CV 2008-10-17: Under debugger control, std fd's have been potentially + initialized in dtable::get_debugger_info (). In this case + init_std_file_from_handle is a no-op, so, even if out == err we don't + want to duplicate the handle since it will be unused. */ + if (out == err && (!being_debugged () || !not_open (2))) { /* Since this code is not invoked for forked tasks, we don't have to worry about the close-on-exec flag here. */ -- 2.43.5