Fix problems with coredumps due to ^C when longjmp buffer isn't valid.
authorTom Lane
Fri, 23 Mar 2001 00:36:38 +0000 (00:36 +0000)
committerTom Lane
Fri, 23 Mar 2001 00:36:38 +0000 (00:36 +0000)
Now, we will only catch ^C at times when it is valid.

src/bin/psql/mainloop.c
src/bin/psql/startup.c

index 919a9f5513f1c576ce60605a314d5f20580c5628..ef124d2fa0f8be48f9ad8e8cce8b78635ef4e075 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.37 2001/03/22 04:00:21 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.38 2001/03/23 00:36:38 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "mainloop.h"
@@ -137,6 +137,10 @@ MainLoop(FILE *source)
                break;
            }
        }
+
+       /* establish the control-C handler only after main_loop_jmp is ready */
+       pqsignal(SIGINT, handle_sigint);    /* control-C => cancel */
+
 #endif  /* not WIN32 */
 
        if (slashCmdStatus == CMD_NEWEDIT)
@@ -546,7 +550,8 @@ MainLoop(FILE *source)
    /*
     * Process query at the end of file without a semicolon
     */
-   if (query_buf->len > 0 && !pset.cur_cmd_interactive)
+   if (query_buf->len > 0 && !pset.cur_cmd_interactive &&
+       successResult == EXIT_SUCCESS)
    {
        success = SendQuery(query_buf->data);
 
@@ -556,6 +561,14 @@ MainLoop(FILE *source)
            successResult = EXIT_BADCONN;
    }
 
+   /*
+    * Reset SIGINT handler because main_loop_jmp will be invalid as soon
+    * as we exit this routine.  If there is an outer MainLoop instance,
+    * it will re-enable ^C catching as soon as it gets back to the top
+    * of its loop and resets main_loop_jmp to point to itself.
+    */
+   pqsignal(SIGINT, SIG_DFL);
+
    destroyPQExpBuffer(query_buf);
    destroyPQExpBuffer(previous_buf);
 
index 55ad9692c66d666ce00365f089cab671136ac5b6..5729b3e27e5ac9ceff1f8ebf5bb9e94b443301f6 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.45 2001/03/22 04:00:23 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.46 2001/03/23 00:36:38 tgl Exp $
  */
 #include "postgres_fe.h"
 
@@ -223,10 +223,6 @@ main(int argc, char *argv[])
    SetVariable(pset.vars, "PORT", PQport(pset.db));
    SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding));
 
-#ifndef WIN32
-   pqsignal(SIGINT, handle_sigint);    /* control-C => cancel */
-#endif
-
    /*
     * Now find something to do
     */