From 414808f9e01ce103d2bc67d4ddaa802125ce5512 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Fri, 2 Sep 2005 17:12:37 +0000 Subject: [PATCH] * Makefile.in (CXXFLAGS): Use 'override' to correctly set flags to generate dependencies when invoked from top-level make. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/Makefile.in | 2 +- winsup/cygwin/cygheap.cc | 5 ----- winsup/cygwin/dcrt0.cc | 3 +-- winsup/cygwin/exceptions.cc | 9 ++++++++- winsup/cygwin/fork.cc | 13 +++++++------ winsup/cygwin/heap.cc | 6 ++++-- winsup/cygwin/init.cc | 1 + winsup/cygwin/pinfo.cc | 5 ++--- winsup/cygwin/sigproc.cc | 9 +++++++++ winsup/cygwin/sigproc.h | 3 ++- 11 files changed, 40 insertions(+), 21 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 29e65958a..cc915c1d6 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2005-09-02 Dave Korn + + * Makefile.in (CXXFLAGS): Use 'override' to correctly set flags to + generate dependencies when invoked from top-level make. + 2005-08-28 Christopher Faylor * exceptions.cc (set_process_mask_delta): Conditionalize debugging diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in index c14eb8046..388289735 100644 --- a/winsup/cygwin/Makefile.in +++ b/winsup/cygwin/Makefile.in @@ -55,7 +55,7 @@ CC_FOR_TARGET:=$(CC) CFLAGS=@CFLAGS@ override CFLAGS+=-MMD ${$(*F)_CFLAGS} -fmerge-constants -ftracer $(CCEXTRA) CXX=@CXX@ -CXXFLAGS=@CXXFLAGS@ +override CXXFLAGS=@CXXFLAGS@ AR:=@AR@ AR_FLAGS:=qv diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index 7db84cc5b..6cbdf6ef7 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -158,12 +158,7 @@ cygheap_init () cygheap_protect.init ("cygheap_protect"); if (!cygheap) { -#if 1 cygheap = (init_cygheap *) memset (_cygheap_start, 0, _cygheap_mid - _cygheap_start); -#else - cygheap = (init_cygheap *) _cygheap_start; -#endif - cygheap_max = cygheap; _csbrk (sizeof (*cygheap)); } diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index e88f64a16..1783d5564 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -547,7 +547,7 @@ initial_env () len = GetModuleFileName (NULL, buf, CYG_MAX_PATH); console_printf ("Sleeping %d, pid %u %s\n", ms, GetCurrentProcessId (), buf); Sleep (ms); - if (!strace.active) + if (!strace.active && !dynamically_loaded) { strace.inited = 0; strace.hello (); @@ -634,7 +634,6 @@ dll_crt0_0 () wincap.init (); initial_env (); - init_console_handler (TRUE); init_global_security (); if (!DuplicateHandle (GetCurrentProcess (), GetCurrentProcess (), GetCurrentProcess (), &hMainProc, 0, FALSE, diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 852b5019f..71a8b7513 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -123,7 +123,8 @@ void init_console_handler (BOOL install_handler) { BOOL res; - SetConsoleCtrlHandler (ctrl_c_handler, FALSE); + while (SetConsoleCtrlHandler (ctrl_c_handler, FALSE)) + continue; if (install_handler) res = SetConsoleCtrlHandler (ctrl_c_handler, TRUE); else if (wincap.has_null_console_handler_routine ()) @@ -833,6 +834,7 @@ has_visible_window_station () static BOOL WINAPI ctrl_c_handler (DWORD type) { +console_printf ("%u OUCH!\n", GetCurrentProcessId ()); static bool saw_close; if (!cygwin_finished_initializing) @@ -845,6 +847,11 @@ ctrl_c_handler (DWORD type) _my_tls.remove (INFINITE); +#if 0 + if (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT) + proc_subproc (PROC_KILLFORKED, 0); +#endif + /* Return FALSE to prevent an "End task" dialog box from appearing for each Cygwin process window that's open when the computer is shut down or console window is closed. */ diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc index 785aabd4f..f16eabc32 100644 --- a/winsup/cygwin/fork.cc +++ b/winsup/cygwin/fork.cc @@ -283,8 +283,7 @@ fork_parent (HANDLE&, dll *&first_dll, bool& load_dlls, void *stack_here, child_ pthread::atforkprepare (); - int c_flags = GetPriorityClass (hMainProc) /*| - CREATE_NEW_PROCESS_GROUP*/; + int c_flags = GetPriorityClass (hMainProc); STARTUPINFO si = {0, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL}; /* If we don't have a console, then don't create a console for the @@ -336,7 +335,7 @@ fork_parent (HANDLE&, dll *&first_dll, bool& load_dlls, void *stack_here, child_ /* Remove impersonation */ cygheap->user.deimpersonate (); - syscall_printf ("CreateProcess (%s, %s, 0, 0, 1, %x, 0, 0, %p, %p)", + syscall_printf ("CreateProcess (%s, %s, 0, 0, 1, %p, 0, 0, %p, %p)", myself->progname, myself->progname, c_flags, &si, &pi); bool locked = __malloc_lock (); rc = CreateProcess (myself->progname, /* image to run */ @@ -418,7 +417,8 @@ fork_parent (HANDLE&, dll *&first_dll, bool& load_dlls, void *stack_here, child_ /* Wait for subproc to initialize itself. */ if (!ch.sync (child->pid, pi.hProcess, FORK_WAIT_TIMEOUT)) { - system_printf ("child %d died waiting for longjmp before initialization", child_pid); + if (NOTSTATE (child, PID_EXITED)) + system_printf ("child %d died waiting for longjmp before initialization", child_pid); goto cleanup; } @@ -469,7 +469,8 @@ fork_parent (HANDLE&, dll *&first_dll, bool& load_dlls, void *stack_here, child_ goto cleanup; else if (!ch.sync (child->pid, pi.hProcess, FORK_WAIT_TIMEOUT)) { - system_printf ("child %d died waiting for dll loading", child_pid); + if (NOTSTATE (child, PID_EXITED)) + system_printf ("child %d died waiting for dll loading", child_pid); goto cleanup; } @@ -506,7 +507,7 @@ fork_parent (HANDLE&, dll *&first_dll, bool& load_dlls, void *stack_here, child_ __malloc_unlock (); /* Remember to de-allocate the fd table. */ - if (pi.hProcess) + if (pi.hProcess && !child.hProcess) ForceCloseHandle1 (pi.hProcess, childhProc); if (pi.hThread) ForceCloseHandle (pi.hThread); diff --git a/winsup/cygwin/heap.cc b/winsup/cygwin/heap.cc index 9f86f9911..bd1b2e3c2 100644 --- a/winsup/cygwin/heap.cc +++ b/winsup/cygwin/heap.cc @@ -34,9 +34,11 @@ extern "C" size_t getpagesize (); void heap_init () { +static int seen = 0; /* If we're the forkee, we must allocate the heap at exactly the same place as our parent. If not, we don't care where it ends up. */ +seen++; page_const = system_info.dwPageSize; if (!cygheap->user_heap.base) { @@ -73,11 +75,11 @@ heap_init () MEM_RESERVE, PAGE_READWRITE); if (p) break; - if ((reserve_size -= page_const) <= allocsize) + if ((reserve_size -= page_const) < allocsize) break; } if (!p) - api_fatal ("couldn't allocate cygwin heap, %E, base %p, top %p, " + api_fatal ("couldn't allocate heap, %E, base %p, top %p, " "reserve_size %d, allocsize %d, page_const %d", cygheap->user_heap.base, cygheap->user_heap.top, reserve_size, allocsize, page_const); diff --git a/winsup/cygwin/init.cc b/winsup/cygwin/init.cc index 491a9d2e3..cad51cc8e 100644 --- a/winsup/cygwin/init.cc +++ b/winsup/cygwin/init.cc @@ -147,6 +147,7 @@ dll_entry (HANDLE h, DWORD reason, void *static_load) case DLL_PROCESS_ATTACH: cygwin_hmodule = (HMODULE) h; dynamically_loaded = (static_load == NULL); + init_console_handler (TRUE); /* Is the stack at an unusual address? This is, an address which is in the usual space occupied by the process image, but below diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 1a08f575b..0e89ca03b 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -1196,8 +1196,7 @@ winpids::add (DWORD& nelem, bool winpid, DWORD pid) pinfolist = (pinfo *) realloc (pinfolist, size_pinfolist (npidlist + 1)); } - pinfolist[nelem].init (cygpid, PID_NOREDIR | (winpid ? PID_ALLPIDS : 0) - | pinfo_access, NULL); + pinfolist[nelem].init (cygpid, PID_NOREDIR | pinfo_access, NULL); if (winpid) goto out; @@ -1205,7 +1204,7 @@ winpids::add (DWORD& nelem, bool winpid, DWORD pid) { if (!pinfo_access) return; - pinfolist[nelem].init (cygpid, PID_NOREDIR | (winpid ? PID_ALLPIDS : 0), NULL); + pinfolist[nelem].init (cygpid, PID_NOREDIR, NULL); if (!pinfolist[nelem]) return; } diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 74ffed179..c7752b882 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -346,6 +346,15 @@ proc_subproc (DWORD what, DWORD val) if (global_sigs[SIGCHLD].sa_handler == (void *) SIG_IGN) for (int i = 0; i < nprocs; i += remove_proc (i)) continue; + break; + case PROC_KILLFORKED: + for (int i = 0; i < nprocs; i++) + if (ISSTATE (procs[i], PID_INITIALIZING)) + { + TerminateProcess (procs[i].hProcess, 1); + procs[i]->process_state = PID_EXITED; + } + break; } out: diff --git a/winsup/cygwin/sigproc.h b/winsup/cygwin/sigproc.h index 74d8d3bfb..2112d79a6 100644 --- a/winsup/cygwin/sigproc.h +++ b/winsup/cygwin/sigproc.h @@ -34,7 +34,8 @@ enum procstuff PROC_DETACHED_CHILD = 2, // set up a detached child PROC_CLEARWAIT = 3, // clear all waits - signal arrived PROC_WAIT = 4, // setup for wait() for subproc - PROC_NOTHING = 5 // nothing, really + PROC_KILLFORKED = 5, // kill forked children on CTRL-C. + PROC_NOTHING = 6 // nothing, really }; struct sigpacket