aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2004-11-21 04:39:13 +0000
committerChristopher Faylor <me@cgf.cx>2004-11-21 04:39:13 +0000
commitfcba9e3c4c63a116777e9af5a03c32c94c07a97d (patch)
treee3e0a4c371543ce67d31abab76e36f208681f209
parent6a6490181f4c85343fdda54d63689b5d47ba5a39 (diff)
downloadnewlib-fcba9e3c4c63a116777e9af5a03c32c94c07a97d.zip
newlib-fcba9e3c4c63a116777e9af5a03c32c94c07a97d.tar.gz
newlib-fcba9e3c4c63a116777e9af5a03c32c94c07a97d.tar.bz2
* cygheap.h (init_cygheap::pid_handle): New element.
* pinfo.cc (set_myself): Clear previously existing cygheap->pid_handle when a new process has been started. (pinfo::wait): Make sure that a handle to the newly forked/spawned process is kept around so that the pid will not be reused. * pinfo.h (_pinfo::pid_handle): Move. (pinfo::pid_handle): to here. * spawn.cc (spawn_guts): Create a pid_handle in cygheap prior to spawning to ensure that the pid does not get reused during the lifetime of the "cygwin pid".
-rw-r--r--winsup/cygwin/ChangeLog13
-rw-r--r--winsup/cygwin/cygheap.h1
-rw-r--r--winsup/cygwin/pinfo.cc11
-rw-r--r--winsup/cygwin/pinfo.h5
-rw-r--r--winsup/cygwin/spawn.cc4
5 files changed, 31 insertions, 3 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 02010f1..0fe827b 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,18 @@
2004-11-20 Christopher Faylor <cgf@timesys.com>
+ * cygheap.h (init_cygheap::pid_handle): New element.
+ * pinfo.cc (set_myself): Clear previously existing cygheap->pid_handle
+ when a new process has been started.
+ (pinfo::wait): Make sure that a handle to the newly forked/spawned
+ process is kept around so that the pid will not be reused.
+ * pinfo.h (_pinfo::pid_handle): Move.
+ (pinfo::pid_handle): to here.
+ * spawn.cc (spawn_guts): Create a pid_handle in cygheap prior to
+ spawning to ensure that the pid does not get reused during the lifetime
+ of the "cygwin pid".
+
+2004-11-20 Christopher Faylor <cgf@timesys.com>
+
* pinfo.h (pinfo::alert_parent): New function.
* exceptions.cc (sig_handle_tty_stop): Use alert_parent to send
"signals" to parent.
diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h
index 2feff85..6351451 100644
--- a/winsup/cygwin/cygheap.h
+++ b/winsup/cygwin/cygheap.h
@@ -281,6 +281,7 @@ struct init_cygheap
size_t sthreads;
int open_fhs;
pid_t pid; /* my pid */
+ HANDLE pid_handle; /* handle for my pid */
void close_ctty ();
};
diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc
index 6af9cd6..acab4e5 100644
--- a/winsup/cygwin/pinfo.cc
+++ b/winsup/cygwin/pinfo.cc
@@ -59,14 +59,18 @@ set_myself (HANDLE h)
myself->dwProcessId = GetCurrentProcessId ();
if (h)
{
+ /* here if execed */
static pinfo NO_COPY myself_identity;
myself_identity.init (cygwin_pid (myself->dwProcessId), PID_EXECED);
}
else if (myself->ppid)
{
+ /* here if forked/spawned */
pinfo parent (myself->ppid);
if (parent && parent->wr_proc_pipe)
CloseHandle (parent->wr_proc_pipe);
+ if (cygheap->pid_handle)
+ CloseHandle (cygheap->pid_handle);
}
return;
}
@@ -784,6 +788,13 @@ 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 ();
diff --git a/winsup/cygwin/pinfo.h b/winsup/cygwin/pinfo.h
index a0cf363..8c4784d 100644
--- a/winsup/cygwin/pinfo.h
+++ b/winsup/cygwin/pinfo.h
@@ -40,9 +40,6 @@ public:
#define PINFO_REDIR_SIZE ((char *) &myself.procinfo->exitcode - (char *) myself.procinfo)
- /* Handle associated with initial Windows pid which started it all. */
- HANDLE pid_handle;
-
/* > 0 if started by a cygwin process */
DWORD cygstarted;
@@ -130,6 +127,8 @@ public:
HANDLE rd_proc_pipe;
HANDLE hProcess;
CRITICAL_SECTION lock;
+ /* Handle associated with initial Windows pid which started it all. */
+ HANDLE pid_handle;
void init (pid_t, DWORD, HANDLE = NULL) __attribute__ ((regparm(3)));
pinfo () {}
pinfo (_pinfo *x): procinfo (x) {}
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index bebbf22..99ff063 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -624,6 +624,10 @@ 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))
+ system_printf ("duplicate to pid_handle failed, %E");
}
/* Some file types (currently only sockets) need extra effort in the