Ensure that we only create one ConsoleCtrlHandler per psql process,
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 4 Nov 2005 18:35:51 +0000 (18:35 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 4 Nov 2005 18:35:51 +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 374e69c4937b09bd3056699f011b96c2acf2d83d..89468fb0fa7477104ce98e9d9d9c6d8b3fec36fe 100644 (file)
@@ -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 */