From e9a6f9c6259960156a999ab2b207adf7ede1a088 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 20 Mar 2012 02:08:14 +0000 Subject: [PATCH] * pinfo.cc (pinfo_init): Cosmetic change: unset "destroy" for myself. (pinfo::wait): Change some comments. (pinfo::prefork): Move a comment. (pinfo::postfork): Set pending_*_pipe variables to NULL if closed. (pinfo::postexec): Use right name when closing handle. (_pinfo::alert_parent): Ditto. * sigproc.h (hold_everything): Remove debugging label. --- winsup/cygwin/ChangeLog | 10 ++++++++++ winsup/cygwin/pinfo.cc | 25 ++++++++++++++++++------- winsup/cygwin/sigproc.h | 1 - 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 65cbdb002..96592d32a 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,13 @@ +2012-03-19 Christopher Faylor + + * pinfo.cc (pinfo_init): Cosmetic change: unset "destroy" for myself. + (pinfo::wait): Change some comments. + (pinfo::prefork): Move a comment. + (pinfo::postfork): Set pending_*_pipe variables to NULL if closed. + (pinfo::postexec): Use right name when closing handle. + (_pinfo::alert_parent): Ditto. + * sigproc.h (hold_everything): Remove debugging label. + 2012-03-19 Christopher Faylor * cygserver_ipc.h: Include sigproc.h for signal_arrived declaration. diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index bc0de4735..10910f3ce 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -117,6 +117,7 @@ pinfo_init (char **envp, int envc) myself->process_state |= PID_ACTIVE; myself->process_state &= ~(PID_INITIALIZING | PID_EXITED | PID_REAPED); + myself.preserve (); debug_printf ("pid %d, pgid %d", myself->pid, myself->pgid); } @@ -933,6 +934,7 @@ proc_waiter (void *arg) case __ALERT_ALIVE: continue; case 0: +debug_printf ("%d exited buf %d\n", vchild->pid, buf); /* Child exited. Do some cleanup and signal myself. */ vchild.maybe_set_exit_code_from_windows (); if (WIFEXITED (vchild->exitcode)) @@ -987,11 +989,17 @@ proc_waiter (void *arg) bool pinfo::wait () { + /* If pending_rd_proc_pipe == NULL we're in an execed process which has + already grabbed the read end of the pipe from the previous cygwin process + running with this pid. */ if (pending_rd_proc_pipe) { + /* Our end of the pipe, previously set in prefork() . */ rd_proc_pipe = pending_rd_proc_pipe; pending_rd_proc_pipe = NULL; + /* This sets wr_proc_pipe in the child which, after the following + ForceCloseHandle1, will be only process with the handle open. */ wr_proc_pipe () = pending_wr_proc_pipe; ForceCloseHandle1 (pending_wr_proc_pipe, wr_proc_pipe); pending_wr_proc_pipe = NULL; @@ -1020,9 +1028,6 @@ pinfo::prefork (bool detached) if (wr_proc_pipe () && wr_proc_pipe () != INVALID_HANDLE_VALUE && !SetHandleInformation (wr_proc_pipe (), HANDLE_FLAG_INHERIT, 0)) api_fatal ("couldn't set process pipe(%p) inherit state, %E", wr_proc_pipe ()); - /* If rd_proc_pipe != NULL we're in an execed process which already has - grabbed the read end of the pipe from the previous cygwin process running - with this pid. */ if (!detached) { if (!CreatePipe (&pending_rd_proc_pipe, &pending_wr_proc_pipe, @@ -1046,16 +1051,22 @@ pinfo::postfork () HANDLE_FLAG_INHERIT)) api_fatal ("postfork: couldn't set process pipe(%p) inherit state, %E", wr_proc_pipe ()); if (pending_rd_proc_pipe) - ForceCloseHandle1 (pending_rd_proc_pipe, rd_proc_pipe); + { + ForceCloseHandle1 (pending_rd_proc_pipe, rd_proc_pipe); + pending_rd_proc_pipe = NULL; + } if (pending_wr_proc_pipe) - ForceCloseHandle1 (pending_wr_proc_pipe, wr_proc_pipe); + { + ForceCloseHandle1 (pending_wr_proc_pipe, wr_proc_pipe); + pending_wr_proc_pipe = NULL; + } } void pinfo::postexec () { if (wr_proc_pipe () && wr_proc_pipe () != INVALID_HANDLE_VALUE - && !ForceCloseHandle (wr_proc_pipe ())) + && !ForceCloseHandle1 (wr_proc_pipe (), wr_proc_pipe)) api_fatal ("postexec: couldn't close wr_proc_pipe(%p), %E", wr_proc_pipe ()); } @@ -1084,7 +1095,7 @@ _pinfo::alert_parent (char sig) ppid = 1; HANDLE closeit = wr_proc_pipe; wr_proc_pipe = INVALID_HANDLE_VALUE; - CloseHandle (closeit); + ForceCloseHandle1 (closeit, wr_proc_pipe); } } return (bool) nb; diff --git a/winsup/cygwin/sigproc.h b/winsup/cygwin/sigproc.h index ffe75a8d3..a86c6bc42 100644 --- a/winsup/cygwin/sigproc.h +++ b/winsup/cygwin/sigproc.h @@ -166,7 +166,6 @@ public: class hold_everything { -public: /* DELETEME*/ bool ischild; /* Note the order of the locks below. It is important, to avoid races, that the lock order be preserved.