diff options
| author | Neil Conway | 2004-02-08 22:28:57 +0000 |
|---|---|---|
| committer | Neil Conway | 2004-02-08 22:28:57 +0000 |
| commit | f06e79525a57ccbf54ae5d0b673cd904ca978d67 (patch) | |
| tree | 88e84b43a0eaa593dffa0f454bfef23ce49cd9d2 /src/backend/libpq/pqsignal.c | |
| parent | 04e82e500868c3e8582f797d7b54a44fcc750a68 (diff) | |
Win32 signals cleanup. Patch by Magnus Hagander, with input from Claudio
Natoli and Bruce Momjian (and some cosmetic fixes from Neil Conway).
Changes:
- remove duplicate signal definitions from pqsignal.h
- replace pqkill() with kill() and redefine kill() in Win32
- use ereport() in place of fprintf() in some error handling in
pqsignal.c
- export pg_queue_signal() and make use of it where necessary
- add a console control handler for Ctrl-C and similar handling
on Win32
- do WaitForSingleObjectEx() in CHECK_FOR_INTERRUPTS() on Win32;
query cancelling should now work on Win32
- various other fixes and cleanups
Diffstat (limited to 'src/backend/libpq/pqsignal.c')
| -rw-r--r-- | src/backend/libpq/pqsignal.c | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/src/backend/libpq/pqsignal.c b/src/backend/libpq/pqsignal.c index 449d25d9ddf..7c4e67ffcce 100644 --- a/src/backend/libpq/pqsignal.c +++ b/src/backend/libpq/pqsignal.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/libpq/pqsignal.c,v 1.30 2004/01/27 00:46:58 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/libpq/pqsignal.c,v 1.31 2004/02/08 22:28:56 neilc Exp $ * * NOTES * This shouldn't be in libpq, but the monitor and some other @@ -39,17 +39,12 @@ * at all. * ------------------------------------------------------------------------*/ #ifdef WIN32 -#define WIN32_LEAN_AND_MEAN #define _WIN32_WINNT 0x0400 #endif #include "postgres.h" -#ifndef WIN32 #include <signal.h> -#else -#include <windows.h> -#endif #include "libpq/pqsignal.h" @@ -180,6 +175,7 @@ HANDLE pgwin32_main_thread_handle; /* Signal handling thread function */ static DWORD WINAPI pg_signal_thread(LPVOID param); +static BOOL WINAPI pg_console_handler(DWORD dwCtrlType); /* Initialization */ void @@ -202,18 +198,18 @@ pgwin32_signal_initialize(void) if (!DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &pgwin32_main_thread_handle, 0, FALSE, DUPLICATE_SAME_ACCESS)) - { - fprintf(stderr, gettext("Failed to get main thread handle!\n")); - exit(1); - } - + ereport(FATAL, + (errmsg_internal("Failed to get main thread handle!"))); + /* Create thread for handling signals */ signal_thread_handle = CreateThread(NULL, 0, pg_signal_thread, NULL, 0, NULL); if (signal_thread_handle == NULL) - { - fprintf(stderr, gettext("Failed to create signal handler thread!\n")); - exit(1); - } + ereport(FATAL, + (errmsg_internal("Failed to create signal handler thread!"))); + + if (!SetConsoleCtrlHandler(pg_console_handler, TRUE)) + ereport(FATAL, + (errmsg_internal("Failed to set console control handler!"))); } @@ -344,7 +340,7 @@ pg_signal_apc(ULONG_PTR param) */ -static void +void pg_queue_signal(int signum) { if (signum >= PG_SIGNAL_COUNT || signum < 0) @@ -430,4 +426,20 @@ pg_signal_thread(LPVOID param) } +/* Console control handler will execute on a thread created + by the OS at the time of invocation */ +static BOOL WINAPI pg_console_handler(DWORD dwCtrlType) { + printf("Console handler being called!\n"); + fflush(stdout); + if (dwCtrlType == CTRL_C_EVENT || + dwCtrlType == CTRL_BREAK_EVENT || + dwCtrlType == CTRL_CLOSE_EVENT || + dwCtrlType == CTRL_SHUTDOWN_EVENT) { + pg_queue_signal(SIGINT); + return TRUE; + } + return FALSE; +} + + #endif |
