Cygwin: processes: use dedicated Cygwin PID rather than Windows PID
Using the Windows PID as Cygwin PID has a few drawbacks: - the PIDs on Windows get reused quickly. Some POSIX applications choke on that, so we need extra code to avoid too quick PID reuse. - The code to avoid PID reuse keeps parent process handles and (depending on a build option) child processes open unnecessarily. - After an execve, the process has a split personality: Its Windows PID is a new PID, while its Cygwin PID is the PID of the execve caller process. This requires to keep two procinfo shared sections open, the second just to redirect process info requests to the first, correct one. This patch changes the way Cygwin PIDs are generated: - Cygwin PIDs are generated independently of the Windows PID, in a way expected by POSIX processes. The PIDs are created incrementally in the range between 2 and 65535, round-robin. - On startup of the first Cygwin process, choose a semi-random start PID for the first process in the lower PID range to make the PIDs slightly unpredictable. This may not be necessary but it seems kind of inviting to know that the first Cygwin process always starts with PID 2. - Every process not only creates the shared procinfo section, but also a symlink in the NT namespace, symlinking the Windows PID to the Cygwin PID. This drops the need for the extra procinfo section after execve. - Don't keep other process handles around unnecessarily. - Simplify the code creating/opening the shared procinfo section and make a clear distinction between interfaces getting a Cygwin PID and interfaces getting a Windows PID. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
@ -209,35 +209,6 @@ frok::child (volatile char * volatile here)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define NO_SLOW_PID_REUSE
|
||||
#ifndef NO_SLOW_PID_REUSE
|
||||
static void
|
||||
slow_pid_reuse (HANDLE h)
|
||||
{
|
||||
static NO_COPY HANDLE last_fork_procs[NPIDS_HELD];
|
||||
static NO_COPY unsigned nfork_procs;
|
||||
|
||||
if (nfork_procs >= (sizeof (last_fork_procs) / sizeof (last_fork_procs [0])))
|
||||
nfork_procs = 0;
|
||||
/* Keep a list of handles to child processes sitting around to prevent
|
||||
Windows from reusing the same pid n times in a row. Having the same pids
|
||||
close in succesion confuses bash. Keeping a handle open will stop
|
||||
windows from reusing the same pid. */
|
||||
if (last_fork_procs[nfork_procs])
|
||||
ForceCloseHandle1 (last_fork_procs[nfork_procs], fork_stupidity);
|
||||
if (DuplicateHandle (GetCurrentProcess (), h,
|
||||
GetCurrentProcess (), &last_fork_procs[nfork_procs],
|
||||
0, FALSE, DUPLICATE_SAME_ACCESS))
|
||||
ProtectHandle1 (last_fork_procs[nfork_procs], fork_stupidity);
|
||||
else
|
||||
{
|
||||
last_fork_procs[nfork_procs] = NULL;
|
||||
system_printf ("couldn't create last_fork_proc, %E");
|
||||
}
|
||||
nfork_procs++;
|
||||
}
|
||||
#endif
|
||||
|
||||
int __stdcall
|
||||
frok::parent (volatile char * volatile stack_here)
|
||||
{
|
||||
@ -437,10 +408,6 @@ frok::parent (volatile char * volatile stack_here)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
#ifndef NO_SLOW_PID_REUSE
|
||||
slow_pid_reuse (hchild);
|
||||
#endif
|
||||
|
||||
/* CHILD IS STOPPED */
|
||||
debug_printf ("child is alive (but stopped)");
|
||||
|
||||
|
Reference in New Issue
Block a user