From: Tom Lane Date: Fri, 23 Mar 2001 00:36:38 +0000 (+0000) Subject: Fix problems with coredumps due to ^C when longjmp buffer isn't valid. X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=f93edb31066002846c62ca252b7bdb06c52625ca;p=users%2Fbernd%2Fpostgres.git Fix problems with coredumps due to ^C when longjmp buffer isn't valid. Now, we will only catch ^C at times when it is valid. --- diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c index f1c3f190e0..18166f3d2e 100644 --- a/src/bin/psql/mainloop.c +++ b/src/bin/psql/mainloop.c @@ -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); diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 80245253cf..d448944baf 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -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 */