Ensure that we only create one ConsoleCtrlHandler per psql process,
authorTom Lane
Fri, 4 Nov 2005 18:35:40 +0000 (18:35 +0000)
committerTom Lane
Fri, 4 Nov 2005 18:35:40 +0000 (18:35 +0000)
so as to avoid performance issues and possible ultimate crash on long
psql scripts.  Per Merlin Moncure.

src/bin/psql/common.c

index 1b01a97d885f98d1e2b6dd3d4135e6945e0ee65c..bddbd7e539f939c9e8e4794d69f436d8bf25ed86 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.109 2005/10/27 13:34:47 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.110 2005/11/04 18:35:40 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "common.h"
@@ -268,6 +268,7 @@ handle_sigint(SIGNAL_ARGS)
    }
    errno = save_errno;         /* just in case the write changed it */
 }
+
 #else                          /* WIN32 */
 
 static BOOL WINAPI
@@ -313,8 +314,16 @@ setup_win32_locks(void)
 void
 setup_cancel_handler(void)
 {
-   SetConsoleCtrlHandler(consoleHandler, TRUE);
+   static bool done = false;
+
+   /* only need one handler per process */
+   if (!done)
+   {
+       SetConsoleCtrlHandler(consoleHandler, TRUE);
+       done = true;
+   }
 }
+
 #endif   /* WIN32 */