* From: Amit Kapila > Another thing to decide about this fix is that whether it is okay to fix > it for CTRL+C and leave the problem open for CTRL+BREAK? > (The current option used (CREATE_NEW_PROCESS_GROUP) will handle only > CTRL+C).
I can think of three situations in which a postgres process can run on Windows: - single backend - console background via pg_ctl - service The only way to deliver a console event to a service process is by calling GenerateConsoleCtrlEvent() with that process( group)'s PID. If anyone does that, they will know what they are doing, so we can disregard that. The other two are tricky. In single-backend mode, we probably expect both to work as usual (ending the process), while in the pg_ctl case, they should both be ignored. Ignoring Ctrl-C in the postmaster and all children is simple, this is what my patch does. Ctrl-Break is more difficult to do. It is not limited to the "foreground" process group, but is delivered to all processes attached to the console that originates it. To ignore it, every process (postmaster, backends, workers, etc.) will have to handle it in their own console event handling function. backend/port/win32/signal.c explicitly turns several of the console events, including Ctrl-C and Ctrl-Break, into SIGINT. The simplest fix would be to ignore Ctrl-Break there, effectively disabling it entirely under all circumstances. I tried that, and it appears to work, but I don't know enough about the signal emulation and the interactions between the various processes to be sure this is the right place to do it. Single-backend mode has no need for signal handling and does not use the emulation layer, so it is unaffected. Below is a new (right now very much proof-of-concept) patch to replace my earlier one. It has the same effect on Ctrl-C the change to pg_ctl had, and additionally ignores Ctrl-Break as well. Please be gentle. diff --git a/src/backend/port/win32/signal.c b/src/backend/port/win32/signal.c index 322b857..7ce5051 100644 --- a/src/backend/port/win32/signal.c +++ b/src/backend/port/win32/signal.c @@ -347,8 +347,12 @@ static BOOL WINAPI pg_console_handler(DWORD dwCtrlType) { if (dwCtrlType == CTRL_C_EVENT || - dwCtrlType == CTRL_BREAK_EVENT || - dwCtrlType == CTRL_CLOSE_EVENT || + dwCtrlType == CTRL_BREAK_EVENT) + { + /* Ignore */ + return TRUE; + } + else if (dwCtrlType == CTRL_CLOSE_EVENT || dwCtrlType == CTRL_SHUTDOWN_EVENT) { pg_queue_signal(SIGINT); -- Christian -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers