From db3137ccb5d3c7499a665d17abf84cf523146cbf Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 14 Oct 2003 09:21:55 +0000 Subject: [PATCH] * exceptions.cc (ctrl_c_handler): Don't send SIGHUP on CTRL_LOGOFF_EVENT to processes running in invisible Windows Stations. * window.cc (has_visible_window_station): New function. * winsup.h: Add declaration for has_visible_window_station. --- winsup/cygwin/ChangeLog | 7 +++++++ winsup/cygwin/exceptions.cc | 22 +++++++++++++++++----- winsup/cygwin/window.cc | 20 ++++++++++++++++++++ winsup/cygwin/winsup.h | 2 ++ 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index f106d3fe5..c832d9f9e 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2003-10-14 Corinna Vinschen + + * exceptions.cc (ctrl_c_handler): Don't send SIGHUP on + CTRL_LOGOFF_EVENT to processes running in invisible Windows Stations. + * window.cc (has_visible_window_station): New function. + * winsup.h: Add declaration for has_visible_window_station. + 2003-10-10 Christopher Faylor * fhandler_tty.cc (fhandler_tty_slave::open): Don't create a new window diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 24b452be7..65d57b361 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -12,6 +12,8 @@ details. */ #include #include #include +#include +#include #include "exceptions.h" #include "sync.h" @@ -919,13 +921,23 @@ ctrl_c_handler (DWORD type) return FALSE; } - if (myself->ctty != -1 - && (type == CTRL_CLOSE_EVENT || (!saw_close && type == CTRL_LOGOFF_EVENT))) + if (myself->ctty != -1) { if (type == CTRL_CLOSE_EVENT) - saw_close = true; - sig_send (NULL, SIGHUP); - return FALSE; + { + saw_close = true; + sig_send (NULL, SIGHUP); + return FALSE; + } + if (!saw_close && type == CTRL_LOGOFF_EVENT) + { + /* Check if the process is actually associated with a visible + window station, one which actually represents a visible desktop. + If not, the CTRL_LOGOFF_EVENT doesn't concern this process. */ + if (has_visible_window_station ()) + sig_send (NULL, SIGHUP); + return FALSE; + } } /* If we are a stub and the new process has a pinfo structure, let it diff --git a/winsup/cygwin/window.cc b/winsup/cygwin/window.cc index ea9ed6e04..3f9462509 100644 --- a/winsup/cygwin/window.cc +++ b/winsup/cygwin/window.cc @@ -247,3 +247,23 @@ ualarm (useconds_t value, useconds_t interval) return (otimer.it_value.tv_sec * 1000000) + otimer.it_value.tv_usec; } +bool +has_visible_window_station (void) +{ + HWINSTA station_hdl; + USEROBJECTFLAGS uof; + DWORD len; + + /* Check if the process is associated with a visible window station. + These are processes running on the local desktop as well as processes + running in terminal server sessions. + Processes running in a service session not explicitely associated + with the desktop (using the "Allow service to interact with desktop" + property) are running in an invisible window station. */ + if ((station_hdl = GetProcessWindowStation ()) + && GetUserObjectInformationA (station_hdl, UOI_FLAGS, &uof, + sizeof uof, &len) + && (uof.dwFlags & WSF_VISIBLE)) + return true; + return false; +} diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h index 5a6f65dc9..745519ea1 100644 --- a/winsup/cygwin/winsup.h +++ b/winsup/cygwin/winsup.h @@ -200,6 +200,8 @@ void __stdcall close_all_files (void); /* Invisible window initialization/termination. */ HWND __stdcall gethwnd (void); +/* Check if running in a visible window station. */ +extern bool has_visible_window_station (void); /* Globals that handle initialization of winsock in a child process. */ extern HANDLE wsock32_handle;