33 *
44 * Copyright 2000 by PostgreSQL Global Development Group
55 *
6- * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.37 2001/03/22 04: 00:21 momjian Exp $
6+ * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.38 2001/03/23 00:36:38 tgl Exp $
77 */
88#include "postgres_fe.h"
99#include "mainloop.h"
@@ -137,6 +137,10 @@ MainLoop(FILE *source)
137137 break ;
138138 }
139139 }
140+
141+ /* establish the control-C handler only after main_loop_jmp is ready */
142+ pqsignal (SIGINT , handle_sigint ); /* control-C => cancel */
143+
140144#endif /* not WIN32 */
141145
142146 if (slashCmdStatus == CMD_NEWEDIT )
@@ -546,7 +550,8 @@ MainLoop(FILE *source)
546550 /*
547551 * Process query at the end of file without a semicolon
548552 */
549- if (query_buf -> len > 0 && !pset .cur_cmd_interactive )
553+ if (query_buf -> len > 0 && !pset .cur_cmd_interactive &&
554+ successResult == EXIT_SUCCESS )
550555 {
551556 success = SendQuery (query_buf -> data );
552557
@@ -556,6 +561,14 @@ MainLoop(FILE *source)
556561 successResult = EXIT_BADCONN ;
557562 }
558563
564+ /*
565+ * Reset SIGINT handler because main_loop_jmp will be invalid as soon
566+ * as we exit this routine. If there is an outer MainLoop instance,
567+ * it will re-enable ^C catching as soon as it gets back to the top
568+ * of its loop and resets main_loop_jmp to point to itself.
569+ */
570+ pqsignal (SIGINT , SIG_DFL );
571+
559572 destroyPQExpBuffer (query_buf );
560573 destroyPQExpBuffer (previous_buf );
561574
0 commit comments