diff options
author | Christopher Faylor <cgf@redhat.com> | 2004-11-20 05:28:31 +0000 |
---|---|---|
committer | Christopher Faylor <cgf@redhat.com> | 2004-11-20 05:28:31 +0000 |
commit | e6af6486391fdcd6b4a244a7c5565286d3f3a868 (patch) | |
tree | efe28f77b26b7898ca3664a7ec92ebc41c3facb6 | |
parent | aff6eb87fc8eb739e535774d5e0abb1e75899573 (diff) | |
download | gdb-e6af6486391fdcd6b4a244a7c5565286d3f3a868.tar.gz |
fix wait when invoked from non-cygwin process.
-rw-r--r-- | winsup/cygwin/pinfo.cc | 12 | ||||
-rw-r--r-- | winsup/cygwin/sigproc.cc | 3 | ||||
-rw-r--r-- | winsup/cygwin/spawn.cc | 30 |
3 files changed, 29 insertions, 16 deletions
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 781df96d004..c04f09e4a47 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -666,7 +666,7 @@ static DWORD WINAPI proc_waiter (void *arg) { pinfo& vchild = *(pinfo *) arg; - // SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_NORMAL); + extern HANDLE hExeced; siginfo_t si; si.si_signo = SIGCHLD; @@ -699,7 +699,7 @@ proc_waiter (void *arg) { case 0: if (WIFEXITED (vchild->exitcode)) - si.si_sigval.sival_int = CLD_STOPPED; + si.si_sigval.sival_int = CLD_EXITED; else if (WCOREDUMP (vchild->exitcode)) si.si_sigval.sival_int = CLD_DUMPED; else @@ -722,6 +722,13 @@ proc_waiter (void *arg) continue; } + if (hExeced) + { + /* execing. no signals available now. */ + proc_subproc (PROC_CLEARWAIT, 0); + break; + } + /* Send a SIGCHLD to myself. We do this here, rather than in proc_subproc to avoid the proc_subproc lock since the signal thread will eventually be calling proc_subproc and could unnecessarily block. */ @@ -734,6 +741,7 @@ proc_waiter (void *arg) else break; } + sigproc_printf ("exiting wait thread for pid %d", pid); _my_tls._ctinfo->release (); return 0; diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 8dc55972e44..041c880e786 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -764,7 +764,8 @@ remove_proc (int ci) sigproc_printf ("removing procs[%d], pid %d, nprocs %d", ci, procs[ci]->pid, nprocs); - procs[ci].release (); + if (procs[ci] != myself) + procs[ci].release (); if (ci < --nprocs) procs[ci] = procs[nprocs]; return 0; diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 8788e922da0..7f2a9798bad 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -633,7 +633,7 @@ spawn_guts (const char * prog_arg, const char *const *argv, parent after CreateProcess and before copying the datastructures to the child. So we have to start the child in suspend state, unfortunately, to avoid a race condition. */ - if (cygheap->fdtab.need_fixup_before ()) + if (!myself->wr_proc_pipe || cygheap->fdtab.need_fixup_before ()) flags |= CREATE_SUSPENDED; const char *runpath = null_app_name ? NULL : (const char *) real_path; @@ -756,11 +756,6 @@ spawn_guts (const char * prog_arg, const char *const *argv, { cygheap->fdtab.fixup_before_exec (pi.dwProcessId); cygheap_setup_for_child_cleanup (newheap, &ciresrv, 1); - if (mode == _P_OVERLAY) - { - ResumeThread (pi.hThread); - cygthread::terminate (); - } } if (mode != _P_OVERLAY) @@ -775,8 +770,10 @@ spawn_guts (const char * prog_arg, const char *const *argv, /* Name the handle similarly to proc_subproc. */ ProtectHandle1 (pi.hProcess, childhProc); + int wait_for_myself = false; if (mode == _P_OVERLAY) { + CloseHandle (saved_sendsig); /* These are both duplicated in the child code. We do this here, primarily for strace. */ strace.execing = 1; @@ -784,6 +781,12 @@ spawn_guts (const char * prog_arg, const char *const *argv, dwExeced = pi.dwProcessId; strcpy (myself->progname, real_path); close_all_files (); + if (!myself->wr_proc_pipe) + { + myself.hProcess = pi.hProcess; + myself.remember (); + wait_for_myself = true; + } } else { @@ -816,19 +819,20 @@ spawn_guts (const char * prog_arg, const char *const *argv, However, we should try to find another way to do this eventually. */ (void) DuplicateHandle (hMainProc, child.shared_handle (), pi.hProcess, NULL, 0, 0, DUPLICATE_SAME_ACCESS); - /* Start the child running */ - ResumeThread (pi.hThread); } + /* Start the child running */ + if (flags & CREATE_SUSPENDED) + ResumeThread (pi.hThread); ForceCloseHandle (pi.hThread); + ForceCloseHandle1 (pi.hProcess, childhProc); sigproc_printf ("spawned windows pid %d", pi.dwProcessId); - bool exited; - - res = 0; - exited = false; - ForceCloseHandle1 (pi.hProcess, childhProc); + if (!wait_for_myself) + res = 0; + else + waitpid (myself->pid, &res, 0); switch (mode) { |