* DevNotes: Add entry cgf-000007.

* child_info.h (child_info_spawn::parent_winpid): Declare new field.
(child_info_spawn::get_parent_handle): Declare new function.
* dcrt0.cc (child_info_spawn::get_parent_handle): Define new function.
(child_info_spawn::handle_spawn): Recreate parent handle if possible when
dynamically loaded.  Don't mess with parent handle if it's NULL.
* spawn.cc (child_info_spawn::worker): Set parent_winpid appropriately.
This commit is contained in:
Christopher Faylor 2012-05-14 22:42:56 +00:00
parent 77009cee1e
commit 3de7be4c1d
6 changed files with 52 additions and 3 deletions

View File

@ -1,3 +1,13 @@
2012-05-14 Christopher Faylor <me.cygwin2012@cgf.cx>
* DevNotes: Add entry cgf-000007.
* child_info.h (child_info_spawn::parent_winpid): Declare new field.
(child_info_spawn::get_parent_handle): Declare new function.
* dcrt0.cc (child_info_spawn::get_parent_handle): Define new function.
(child_info_spawn::handle_spawn): Recreate parent handle if possible
when dynamically loaded. Don't mess with parent handle if it's NULL.
* spawn.cc (child_info_spawn::worker): Set parent_winpid appropriately.
2012-05-12 Christopher Faylor <me.cygwin2012@cgf.cx>
* DevNotes: Add entry cgf-000006.

View File

@ -1,3 +1,26 @@
2012-05-14 cgf-000007
<1.7.16>
- Fix invocation of strace from a cygwin process. Fixes:
http://cygwin.com/ml/cygwin/2012-05/msg00292.html
</1.7.16>
The change in cgf-000004 introduced a problem for processes which load
cygwin1.dll dynamically. strace.exe is the most prominent example of
this.
Since the parent handle is now closed for "non-Cygwin" processes, when
strace.exe tried to dynamically load cygwin1.dll, the handle was invalid
and child_info_spawn::handle_spawn couldn't use retrieve information
from the parent. This eventually led to a strace_printf error due to an
attempt to dereference an unavailable cygheap. Probably have to fix
this someday. You shouldn't use the cygheap while attempting to print
an error about the inavailability of said cygheap.
This was fixed by saving the parent pid in child_info_spawn and calling
OpenProcess for the parent pid and using that handle iff a process is
dynamically loaded.
2012-05-12 cgf-000006
<1.7.16>

View File

@ -66,6 +66,7 @@ public:
HANDLE subproc_ready; // used for synchronization with parent
HANDLE user_h;
HANDLE parent;
DWORD parent_winpid;
DWORD cygheap_reserve_sz;
unsigned fhandler_union_cb;
DWORD exit_code; // process exit code
@ -175,6 +176,7 @@ public:
lock->release ();
return !!hExeced;
}
bool get_parent_handle ();
bool has_execed_cygwin () const { return iscygwin () && has_execed (); }
operator HANDLE& () {return hExeced;}
int worker (const char *, const char *const *, const char *const [], int,

View File

@ -625,13 +625,24 @@ child_info_fork::handle_fork ()
api_fatal ("recreate_mmaps_after_fork_failed");
}
bool
child_info_spawn::get_parent_handle ()
{
parent = OpenProcess (PROCESS_VM_READ, false, parent_winpid);
moreinfo->myself_pinfo = NULL;
return !!parent;
}
void
child_info_spawn::handle_spawn ()
{
extern void fixup_lockf_after_exec ();
HANDLE h;
cygheap_fixup_in_child (true);
memory_init (false);
if (!dynamically_loaded || get_parent_handle ())
{
cygheap_fixup_in_child (true);
memory_init (false);
}
if (!moreinfo->myself_pinfo ||
!DuplicateHandle (GetCurrentProcess (), moreinfo->myself_pinfo,
GetCurrentProcess (), &h, 0,
@ -669,7 +680,7 @@ child_info_spawn::handle_spawn ()
Otherwise, we no longer need this handle so close it.
Need to do this after debug_fixup_after_fork_exec or DEBUGGING handling of
handles might get confused. */
if (type != _CH_EXEC)
if (type != _CH_EXEC && child_proc_info->parent)
{
CloseHandle (child_proc_info->parent);
child_proc_info->parent = NULL;

View File

@ -12,3 +12,5 @@ fifo. Fixes: http://cygwin.com/ml/cygwin/2012-05/msg00253.html
- Fix hang when calling pthread_testcancel in a canceled thread.
Fixes some of: http://cygwin.com/ml/cygwin/2012-05/msg00186.html
- Fix invocation of strace from a cygwin process. Fixes:
http://cygwin.com/ml/cygwin/2012-05/msg00292.html

View File

@ -614,6 +614,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
SetHandleInformation (wr_proc_pipe, HANDLE_FLAG_INHERIT, 0);
SetHandleInformation (parent, HANDLE_FLAG_INHERIT, 0);
}
parent_winpid = GetCurrentProcessId ();
/* When ruid != euid we create the new process under the current original
account and impersonate in child, this way maintaining the different