aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/dumputils.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2012-02-16 11:49:20 -0500
committerRobert Haas <rhaas@postgresql.org>2012-02-16 11:49:20 -0500
commite9a22259c45e235aaa30f0d068f767d9c0f818a0 (patch)
tree35b434f8f3ee8b00e0ee2fd88271f01a7035778d /src/bin/pg_dump/dumputils.c
parent4bfe68dfab009ce8fcaea79dc0832eadf3380051 (diff)
downloadpostgresql-e9a22259c45e235aaa30f0d068f767d9c0f818a0.tar.gz
postgresql-e9a22259c45e235aaa30f0d068f767d9c0f818a0.zip
Invent on_exit_nicely for pg_dump.
Per recent discussions on pgsql-hackers regarding parallel pg_dump.
Diffstat (limited to 'src/bin/pg_dump/dumputils.c')
-rw-r--r--src/bin/pg_dump/dumputils.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c
index 3493e394033..0b24220bd46 100644
--- a/src/bin/pg_dump/dumputils.c
+++ b/src/bin/pg_dump/dumputils.c
@@ -26,6 +26,15 @@
int quote_all_identifiers = 0;
const char *progname = NULL;
+#define MAX_ON_EXIT_NICELY 20
+
+static struct
+{
+ on_exit_nicely_callback function;
+ void *arg;
+} on_exit_nicely_list[MAX_ON_EXIT_NICELY];
+
+static int on_exit_nicely_index;
#define supports_grant_options(version) ((version) >= 70400)
@@ -1261,7 +1270,7 @@ exit_horribly(const char *modulename, const char *fmt,...)
vwrite_msg(modulename, fmt, ap);
va_end(ap);
- exit(1);
+ exit_nicely(1);
}
/*
@@ -1289,6 +1298,27 @@ set_section (const char *arg, int *dumpSections)
progname, arg);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
- exit(1);
+ exit_nicely(1);
}
}
+
+/* Register a callback to be run when exit_nicely is invoked. */
+void
+on_exit_nicely(on_exit_nicely_callback function, void *arg)
+{
+ if (on_exit_nicely_index >= MAX_ON_EXIT_NICELY)
+ exit_horribly(NULL, "out of on_exit_nicely slots");
+ on_exit_nicely_list[on_exit_nicely_index].function = function;
+ on_exit_nicely_list[on_exit_nicely_index].arg = arg;
+ on_exit_nicely_index++;
+}
+
+/* Run accumulated on_exit_nicely callbacks and then exit quietly. */
+void
+exit_nicely(int code)
+{
+ while (--on_exit_nicely_index >= 0)
+ (*on_exit_nicely_list[on_exit_nicely_index].function)(code,
+ on_exit_nicely_list[on_exit_nicely_index].arg);
+ exit(code);
+}