Re: PostgreSQL in Windows console and Ctrl-C

Поиск
Список
Период
Сортировка
От Christian Ullrich
Тема Re: PostgreSQL in Windows console and Ctrl-C
Дата
Msg-id 2e9f08dd3f60446ebc03f67bea445887@AMSPR06MB134.eurprd06.prod.outlook.com
обсуждение исходный текст
Ответ на PostgreSQL in Windows console and Ctrl-C  (Christian Ullrich <chris@chrullrich.net>)
Ответы Re: PostgreSQL in Windows console and Ctrl-C  (Amit Kapila <amit.kapila16@gmail.com>)
Список pgsql-hackers
* 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 WINAPIpg_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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Amit Kapila
Дата:
Сообщение: Re: Dynamic Shared Memory stuff
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: Re: Problem with txid_snapshot_in/out() functionality