summaryrefslogtreecommitdiff
path: root/src/bin/psql/large_obj.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-06-14 16:49:03 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-06-14 16:49:03 +0000
commitf3164c020028de70e4cd991ccbd3d696c9060709 (patch)
tree02b6ad16c4498a1d8609e9237b769e57eb1a6aaf /src/bin/psql/large_obj.c
parentace93353eadf1316364bcb76f52952c413779083 (diff)
Clean up psql's control-C handling to avoid longjmp'ing out of random
places --- that risks corrupting data structures, losing sync with the backend, etc. We now longjmp only from calls to readline, fgets, and fread, which we assume are coded to protect themselves against interrupts at undesirable times. This requires adding explicit tests for cancel_pressed in long-running loops, but on the whole it's far cleaner. Martijn van Oosterhout and Tom Lane.
Diffstat (limited to 'src/bin/psql/large_obj.c')
-rw-r--r--src/bin/psql/large_obj.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/bin/psql/large_obj.c b/src/bin/psql/large_obj.c
index 5de0348b397..9e8d6d2945d 100644
--- a/src/bin/psql/large_obj.c
+++ b/src/bin/psql/large_obj.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/large_obj.c,v 1.43 2006/05/28 21:13:54 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/large_obj.c,v 1.44 2006/06/14 16:49:02 tgl Exp $
*/
#include "postgres_fe.h"
#include "large_obj.h"
@@ -120,10 +120,13 @@ do_lo_export(const char *loid_arg, const char *filename_arg)
if (!start_lo_xact("\\lo_export", &own_transaction))
return false;
+ SetCancelConn();
status = lo_export(pset.db, atooid(loid_arg), filename_arg);
+ ResetCancelConn();
+
+ /* of course this status is documented nowhere :( */
if (status != 1)
- { /* of course this status is documented nowhere
- * :( */
+ {
fputs(PQerrorMessage(pset.db), stderr);
return fail_lo_xact("\\lo_export", own_transaction);
}
@@ -153,7 +156,10 @@ do_lo_import(const char *filename_arg, const char *comment_arg)
if (!start_lo_xact("\\lo_import", &own_transaction))
return false;
+ SetCancelConn();
loid = lo_import(pset.db, filename_arg);
+ ResetCancelConn();
+
if (loid == InvalidOid)
{
fputs(PQerrorMessage(pset.db), stderr);
@@ -211,7 +217,10 @@ do_lo_unlink(const char *loid_arg)
if (!start_lo_xact("\\lo_unlink", &own_transaction))
return false;
+ SetCancelConn();
status = lo_unlink(pset.db, loid);
+ ResetCancelConn();
+
if (status == -1)
{
fputs(PQerrorMessage(pset.db), stderr);