aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2004-11-24 05:48:31 +0000
committerChristopher Faylor <me@cgf.cx>2004-11-24 05:48:31 +0000
commitc373c4a1f13d0814a32a7881be448c7e68e19ce9 (patch)
tree928b18c8e1bfaeb345781ac4987351f3ab028182
parentfcba9e3c4c63a116777e9af5a03c32c94c07a97d (diff)
downloadnewlib-github/noreparent.zip
newlib-github/noreparent.tar.gz
newlib-github/noreparent.tar.bz2
* child_info.h (child_info_spawn::hexec_proc): Eliminate.github/noreparentnoreparent
* dcrt0.cc (dll_crt0_0): Remove hexec_proc stuff. * fork.cc (fork_child): Remove call to pinfo_fixup_after_fork. * pinfo.cc (set_myself): Close and zero pid_handle if set. (pinfo_fixup_after_fork): Delete. (proc_waiter): Don't close vchild.hProcess here. Do that when we are remove the vchild from procs. Save hProcess as pid_handle only on first reparent operation. (pinfo::wait): Don't set pid_handle here. (pinfo::alert_parent): Always try to send signal. If unsuccessful then close and zero wr_proc_pipe. * pinfo.h (pinfo::pinfo): Make sure that appropriate parts of the class are zeroed on construction. (pinfo::alert_parent): Take char argument. (pinfo_fixup_after_fork): Delete declaration. (hexec_proc): Ditto. * sigproc.cc (remove_proc): Close pid_handle and hProcess if appropriate. * spawn.cc (spawn_guts): Set cygheap->pid_handle on first exec.
-rw-r--r--winsup/cygwin/ChangeLog22
-rw-r--r--winsup/cygwin/child_info.h3
-rw-r--r--winsup/cygwin/dcrt0.cc8
-rw-r--r--winsup/cygwin/fork.cc1
-rw-r--r--winsup/cygwin/pinfo.cc63
-rw-r--r--winsup/cygwin/pinfo.h11
-rw-r--r--winsup/cygwin/select.cc2
-rw-r--r--winsup/cygwin/sigproc.cc12
-rw-r--r--winsup/cygwin/spawn.cc10
9 files changed, 65 insertions, 67 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 0fe827b..f928631 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,25 @@
+2004-11-21 Christopher Faylor <cgf@timesys.com>
+
+ * child_info.h (child_info_spawn::hexec_proc): Eliminate.
+ * dcrt0.cc (dll_crt0_0): Remove hexec_proc stuff.
+ * fork.cc (fork_child): Remove call to pinfo_fixup_after_fork.
+ * pinfo.cc (set_myself): Close and zero pid_handle if set.
+ (pinfo_fixup_after_fork): Delete.
+ (proc_waiter): Don't close vchild.hProcess here. Do that when we are
+ remove the vchild from procs. Save hProcess as pid_handle only on
+ first reparent operation.
+ (pinfo::wait): Don't set pid_handle here.
+ (pinfo::alert_parent): Always try to send signal. If unsuccessful then
+ close and zero wr_proc_pipe.
+ * pinfo.h (pinfo::pinfo): Make sure that appropriate parts of the class
+ are zeroed on construction.
+ (pinfo::alert_parent): Take char argument.
+ (pinfo_fixup_after_fork): Delete declaration.
+ (hexec_proc): Ditto.
+ * sigproc.cc (remove_proc): Close pid_handle and hProcess if
+ appropriate.
+ * spawn.cc (spawn_guts): Set cygheap->pid_handle on first exec.
+
2004-11-20 Christopher Faylor <cgf@timesys.com>
* cygheap.h (init_cygheap::pid_handle): New element.
diff --git a/winsup/cygwin/child_info.h b/winsup/cygwin/child_info.h
index e3d643a..7cbcb6f 100644
--- a/winsup/cygwin/child_info.h
+++ b/winsup/cygwin/child_info.h
@@ -29,7 +29,7 @@ enum
#define EXEC_MAGIC_SIZE sizeof(child_info)
-#define CURR_CHILD_INFO_MAGIC 0x568a5527U
+#define CURR_CHILD_INFO_MAGIC 0x83e9a7b7U
/* NOTE: Do not make gratuitous changes to the names or organization of the
below class. The layout is checksummed to determine compatibility between
@@ -82,7 +82,6 @@ class child_info_spawn: public child_info
{
public:
cygheap_exec_info *moreinfo;
- HANDLE hexec_proc;
child_info_spawn (): moreinfo (NULL) {}
~child_info_spawn ()
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 41bd7d6..51b197e 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -645,7 +645,6 @@ dll_crt0_0 ()
memory_init ();
else
{
- bool close_hexec_proc = false;
switch (child_proc_info->type)
{
case _PROC_FORK:
@@ -655,12 +654,7 @@ dll_crt0_0 ()
set_myself (NULL);
break;
case _PROC_SPAWN:
- /* Have to delay closes until after cygheap is setup */
- close_hexec_proc = !!spawn_info->hexec_proc;
- goto around;
case _PROC_EXEC:
- hexec_proc = spawn_info->hexec_proc;
- around:
HANDLE h;
cygheap_fixup_in_child (true);
memory_init ();
@@ -683,8 +677,6 @@ dll_crt0_0 ()
}
break;
}
- if (close_hexec_proc)
- CloseHandle (spawn_info->hexec_proc);
}
_cygtls::init ();
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index 706b854..1dc1e7b 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -284,7 +284,6 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
(void) ForceCloseHandle1 (fork_info->subproc_ready, subproc_ready);
(void) ForceCloseHandle1 (fork_info->forker_finished, forker_finished);
- pinfo_fixup_after_fork ();
_my_tls.fixup_after_fork ();
sigproc_init ();
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index acab4e5..8a19aef 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -37,8 +37,6 @@ static char NO_COPY pinfo_dummy[sizeof (_pinfo)] = {0};
pinfo NO_COPY myself ((_pinfo *)&pinfo_dummy); // Avoid myself != NULL checks
-HANDLE hexec_proc;
-
/* Initialize the process table.
This is done once when the dll is first loaded. */
@@ -70,7 +68,10 @@ set_myself (HANDLE h)
if (parent && parent->wr_proc_pipe)
CloseHandle (parent->wr_proc_pipe);
if (cygheap->pid_handle)
- CloseHandle (cygheap->pid_handle);
+ {
+ ForceCloseHandle (cygheap->pid_handle);
+ cygheap->pid_handle = NULL;
+ }
}
return;
}
@@ -102,21 +103,6 @@ pinfo_init (char **envp, int envc)
debug_printf ("pid %d, pgid %d", myself->pid, myself->pgid);
}
-void __stdcall
-pinfo_fixup_after_fork ()
-{
- if (hexec_proc)
- CloseHandle (hexec_proc);
- /* Keeps the cygpid from being reused. No rights required */
- if (!DuplicateHandle (hMainProc, hMainProc, hMainProc, &hexec_proc, 0,
- TRUE, 0))
- {
- system_printf ("couldn't save current process handle %p, %E", hMainProc);
- hexec_proc = NULL;
- }
- VerifyHandle (hexec_proc);
-}
-
void
_pinfo::exit (UINT n, bool norecord)
{
@@ -711,7 +697,6 @@ proc_waiter (void *arg)
if (GetExitCodeProcess (vchild.hProcess, &exit_code))
vchild->exitcode = (exit_code & 0xff) << 8;
}
- ForceCloseHandle1 (vchild.hProcess, childhProc);
if (WIFEXITED (vchild->exitcode))
si.si_sigval.sival_int = CLD_EXITED;
else if (WCOREDUMP (vchild->exitcode))
@@ -730,15 +715,18 @@ proc_waiter (void *arg)
case SIGCONT:
continue;
case __SIGREPARENT: /* sigh */
- if (vchild.hProcess)
+ if (!vchild.hProcess)
+ /* something went wrong. oh well. */;
+ else if (vchild.pid_handle)
ForceCloseHandle1 (vchild.hProcess, childhProc);
+ else
+ vchild.pid_handle = vchild.hProcess;
vchild.hProcess = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE,
vchild->dwProcessId);
vchild->cygstarted++;
if (vchild.hProcess)
ProtectHandle1 (vchild.hProcess, childhProc);
continue;
- break;
default:
system_printf ("unknown value %d on proc pipe", buf);
continue;
@@ -788,13 +776,6 @@ pinfo::wait ()
hProcess);
return 0;
}
- if (!DuplicateHandle (hMainProc, hProcess, hMainProc, &pid_handle, 0,
- FALSE, DUPLICATE_SAME_ACCESS))
- {
- system_printf ("Couldn't duplicate pipe topid %d(%p), %E", (*this)->pid,
- hProcess);
- return 0;
- }
CloseHandle (out);
preserve ();
@@ -813,21 +794,21 @@ pinfo::wait ()
}
void
-pinfo::alert_parent (int sig)
+pinfo::alert_parent (char sig)
{
- /* See if we have a living parent. If so, send it a special signal.
- It will figure out exactly which pid has stopped by scanning
- its list of subprocesses. */
- if (my_parent_is_alive ())
+ DWORD nb;
+ /* Send something to our parent. If the parent has gone away,
+ close the pipe. */
+ if (myself->wr_proc_pipe
+ && WriteFile (myself->wr_proc_pipe, &sig, 1, &nb, NULL))
+ /* all is well */;
+ else if (GetLastError () != ERROR_BROKEN_PIPE)
+ debug_printf ("sending %d notification to parent failed, %E", sig);
+ else
{
- pinfo parent (myself->ppid);
- if (NOTSTATE (parent, PID_NOCLDSTOP))
- {
- DWORD nb;
- unsigned char pipesig = sig;
- if (!WriteFile (myself->wr_proc_pipe, &pipesig, 1, &nb, NULL))
- debug_printf ("sending %d notification to parent failed, %E", sig);
- }
+ HANDLE closeit = myself->wr_proc_pipe;
+ myself->wr_proc_pipe = NULL;
+ CloseHandle (closeit);
}
}
diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h
index 8c4784d..b062934 100644
--- a/winsup/cygwin/pinfo.h
+++ b/winsup/cygwin/pinfo.h
@@ -131,9 +131,9 @@ public:
HANDLE pid_handle;
void init (pid_t, DWORD, HANDLE = NULL) __attribute__ ((regparm(3)));
pinfo () {}
- pinfo (_pinfo *x): procinfo (x) {}
- pinfo (pid_t n) {init (n, 0);}
- pinfo (pid_t n, DWORD flag) {init (n, flag);}
+ pinfo (_pinfo *x): procinfo (x), hProcess (NULL), pid_handle (NULL) {}
+ pinfo (pid_t n) : rd_proc_pipe (NULL), hProcess (NULL), pid_handle (NULL) {init (n, 0);}
+ pinfo (pid_t n, DWORD flag) : rd_proc_pipe (NULL), hProcess (NULL), pid_handle (NULL) {init (n, flag);}
void release ();
int wait () __attribute__ ((regparm (1)));
~pinfo ()
@@ -153,7 +153,7 @@ public:
operator _pinfo * () const {return procinfo;}
// operator bool () const {return (int) h;}
void preserve () { destroy = false; }
- void alert_parent (int);
+ void alert_parent (char);
#ifndef _SIGPROC_H
int remember () {system_printf ("remember is not here"); return 0;}
#else
@@ -213,9 +213,6 @@ extern pinfo myself;
#define _P_VFORK 0
#define _P_SYSTEM 512
-extern void __stdcall pinfo_fixup_after_fork ();
-extern HANDLE hexec_proc;
-
/* For mmaps across fork(). */
int __stdcall fixup_mmaps_after_fork (HANDLE parent);
/* for shm areas across fork (). */
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index f145e08..c943b2a 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -207,7 +207,7 @@ select_stuff::test_and_set (int i, fd_set *readfds, fd_set *writefds,
if (s->read_ready || s->write_ready || s->except_ready)
always_ready = true;
- if (s->windows_handle || s->windows_handle || s->windows_handle)
+ if (s->windows_handle)
windows_used = true;
s->next = start.next;
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 041c880..844e80a 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -303,8 +303,8 @@ proc_subproc (DWORD what, DWORD val)
*/
if ((wval->ev = wval->thread_ev) == NULL)
{
- wval->ev = wval->thread_ev = CreateEvent (&sec_none_nih, TRUE,
- FALSE, NULL);
+ wval->ev = wval->thread_ev = CreateEvent (&sec_none_nih, TRUE, FALSE,
+ NULL);
ProtectHandle1 (wval->ev, wq_ev);
}
@@ -765,7 +765,13 @@ remove_proc (int ci)
sigproc_printf ("removing procs[%d], pid %d, nprocs %d", ci, procs[ci]->pid,
nprocs);
if (procs[ci] != myself)
- procs[ci].release ();
+ {
+ procs[ci].release ();
+ if (procs[ci].pid_handle)
+ ForceCloseHandle1 (procs[ci].pid_handle, childhProc);
+ if (procs[ci].hProcess)
+ ForceCloseHandle1 (procs[ci].hProcess, childhProc);
+ }
if (ci < --nprocs)
procs[ci] = procs[nprocs];
return 0;
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 99ff063..733b5dc 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -592,7 +592,6 @@ spawn_guts (const char * prog_arg, const char *const *argv,
ciresrv.moreinfo->argc = newargv.argc;
ciresrv.moreinfo->argv = newargv;
- ciresrv.hexec_proc = hexec_proc;
if (mode != _P_OVERLAY ||
!DuplicateHandle (hMainProc, myself.shared_handle (), hMainProc,
@@ -624,9 +623,12 @@ spawn_guts (const char * prog_arg, const char *const *argv,
{
saved_sendsig = myself->sendsig;
myself->sendsig = INVALID_HANDLE_VALUE;
- if (!cygheap->pid_handle
- && !DuplicateHandle (hMainProc, hMainProc, hMainProc, &cygheap->pid_handle,
- 0, TRUE, DUPLICATE_SAME_ACCESS))
+ if (cygheap->pid_handle)
+ /* ok */;
+ else if (DuplicateHandle (hMainProc, hMainProc, hMainProc, &cygheap->pid_handle,
+ PROCESS_QUERY_INFORMATION, TRUE, 0))
+ ProtectHandle (cygheap->pid_handle);
+ else
system_printf ("duplicate to pid_handle failed, %E");
}