diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 8a233f0e0..864b8d88a 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,16 @@ +2002-01-09 Christopher Faylor + Robert Collins + + * exceptions.cc (early_stuff_init): Rename from misnamed + set_console_handler. + (ctrl_c_handler): Attempt to work around potential signal duplication + during process startup. + (sig_handle): Ignore SIGINT when we're just an "exec stub". + * spawn.cc (spawn_guts): Store pid of spawned process in global for use + by ctrl_c_handler. + * dcrt0.cc (dll_crt0_1): Call renamed initialization function. + * winsup.h: Reflect function name change. + 2002-01-08 Corinna Vinschen * net.cc (cygwin_accept): Set sun_path for newly connected socket. diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index c68a2bc12..e90deba3c 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -813,7 +813,7 @@ _dll_crt0 () main_environ = user_data->envptr; *main_environ = NULL; - set_console_handler (); + early_stuff_init (); if (!DuplicateHandle (GetCurrentProcess (), GetCurrentProcess (), GetCurrentProcess (), &hMainProc, 0, FALSE, DUPLICATE_SAME_ACCESS)) diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 0304a4249..a3107e8b3 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -38,6 +38,9 @@ extern DWORD __no_sig_start, __no_sig_end; extern DWORD sigtid; +extern HANDLE hExeced; +extern DWORD dwExeced; + static BOOL WINAPI ctrl_c_handler (DWORD); static void signal_exit (int) __attribute__ ((noreturn)); static char windows_system_directory[1024]; @@ -113,8 +116,12 @@ init_exception_handler (exception_list *el) #endif void -set_console_handler () +early_stuff_init () { + (void) SetConsoleCtrlHandler (ctrl_c_handler, FALSE); + if (!SetConsoleCtrlHandler (ctrl_c_handler, TRUE)) + system_printf ("SetConsoleCtrlHandler failed, %E"); + /* Initialize global security attribute stuff */ sec_none.nLength = sec_none_nih.nLength = @@ -124,10 +131,6 @@ set_console_handler () sec_none.lpSecurityDescriptor = sec_none_nih.lpSecurityDescriptor = NULL; sec_all.lpSecurityDescriptor = sec_all_nih.lpSecurityDescriptor = get_null_sd (); - - (void) SetConsoleCtrlHandler (ctrl_c_handler, FALSE); - if (!SetConsoleCtrlHandler (ctrl_c_handler, TRUE)) - system_printf ("SetConsoleCtrlHandler failed, %E"); } extern "C" void @@ -911,8 +914,18 @@ ctrl_c_handler (DWORD type) return FALSE; } + /* If we are a stub and the new process has a pinfo structure, let it + handle this signal. */ + if (dwExeced && pinfo (dwExeced)) + return TRUE; + + /* We're only the process group leader when we have a valid pinfo structure. + If we don't have one, then the parent "stub" will handle the signal. */ + if (!pinfo (GetCurrentProcessId ())) + return TRUE; + tty_min *t = cygwin_shared->tty.get_tty (myself->ctty); - /* Ignore this if we're not the process group lead since it should be handled + /* Ignore this if we're not the process group leader since it should be handled *by* the process group leader. */ if (myself->ctty != -1 && t->getpgid () == myself->pid && (GetTickCount () - t->last_ctrl_c) >= MIN_CTRL_C_SLOP) @@ -925,6 +938,7 @@ ctrl_c_handler (DWORD type) t->last_ctrl_c = GetTickCount (); return TRUE; } + return TRUE; } @@ -997,7 +1011,7 @@ sig_handle (int sig) if (handler == (void *) SIG_DFL) { if (sig == SIGCHLD || sig == SIGIO || sig == SIGCONT || sig == SIGWINCH - || sig == SIGURG) + || sig == SIGURG || (hExeced && sig == SIGINT)) { sigproc_printf ("default signal %d ignored", sig); goto done; @@ -1060,8 +1074,6 @@ sig_handle (int sig) static void signal_exit (int rc) { - extern HANDLE hExeced; - rc = EXIT_SIGNAL | (rc << 8); if (exit_already++) myself->exit (rc); diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 72fb649bf..c9f1074c9 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -48,6 +48,7 @@ static suffix_info std_suffixes[] = }; HANDLE hExeced; +DWORD dwExeced; /* Add .exe to PROG if not already present and see if that exists. If not, return PROG (converted from posix to win32 rules if necessary). @@ -56,7 +57,7 @@ HANDLE hExeced; Returns (possibly NULL) suffix */ static const char * -perhaps_suffix (const char *prog, path_conv &buf) +perhaps_suffix (const char *prog, path_conv& buf) { char *ext; @@ -760,6 +761,7 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv, primarily for strace. */ strace.execing = 1; hExeced = pi.hProcess; + dwExeced = pi.dwProcessId; strcpy (myself->progname, real_path); close_all_files (); } diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h index d977d6214..64a9dbf69 100644 --- a/winsup/cygwin/winsup.h +++ b/winsup/cygwin/winsup.h @@ -193,7 +193,7 @@ void __stdcall totimeval (struct timeval *dst, FILETIME * src, int sub, int flag long __stdcall to_time_t (FILETIME * ptr); void __stdcall set_console_title (char *); -void set_console_handler (); +void early_stuff_init (); int __stdcall check_null_str (const char *name) __attribute__ ((regparm(1))); int __stdcall check_null_empty_str (const char *name) __attribute__ ((regparm(1)));