From b0de2aa284ccb58f1c8f8e0a598701b51ab5b742 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Sat, 21 Oct 2000 04:53:49 +0000 Subject: * fhandler.h (fhandler_console): Remove tcsetpgrp. * fhandler_console.cc (fhandler_console::tcsetpgrp): Eliminate. * fork.cc (fork_parent): Avoid returning same pid twice in a row regardless of OS. * pinfo.cc (pinfo::init): Rename create argument to flags and treat it as such. * signal.cc (set_sigcatchers): New function. (signal): Use set_sigcatchers to increment or decrement sigcatcher tracker. (sigaction): Ditto. Add debugging output. * spawn.cc (spawn_guts): Always quote first argv[0] argument when it's a COMSPEC shell. --- winsup/cygwin/fork.cc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'winsup/cygwin/fork.cc') diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc index a883ed553..0c8df30cd 100644 --- a/winsup/cygwin/fork.cc +++ b/winsup/cygwin/fork.cc @@ -443,14 +443,17 @@ fork_parent (void *stack_here, HANDLE& hParent, dll *&first_dll, bool& load_dlls /* Protect the handle but name it similarly to the way it will be called in subproc handling. */ ProtectHandle1 (pi.hProcess, childhProc); - if (os_being_run != winNT) - { - if (last_fork_proc) - CloseHandle (last_fork_proc); - if (!DuplicateHandle (hMainProc, pi.hProcess, hMainProc, &last_fork_proc, - 0, FALSE, DUPLICATE_SAME_ACCESS)) - system_printf ("couldn't create last_fork_proc, %E"); - } + + /* Keep a handle to the current forked process sitting around to prevent + Windows from reusing the same pid twice in a row. Having the same pid + twice in a row confuses bash. So, after every CreateProcess, we can safely + remove the old pid and save a handle to the newly created process. Keeping + a handle open will stop windows from reusing the same pid. */ + if (last_fork_proc) + CloseHandle (last_fork_proc); + if (!DuplicateHandle (hMainProc, pi.hProcess, hMainProc, &last_fork_proc, + 0, FALSE, DUPLICATE_SAME_ACCESS)) + system_printf ("couldn't create last_fork_proc, %E"); /* Fill in fields in the child's process table entry. */ forked->ppid = myself->pid; -- cgit v1.2.3