1/*-------------------------------------------------------------------------
4 * Utility routines shared by pg_dump and pg_restore
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/bin/pg_dump/pg_backup_utils.c
12 *-------------------------------------------------------------------------
21/* Globals exported by this file */
24 #define MAX_ON_EXIT_NICELY 20
35 * Parse a --section=foo command line argument.
37 * Set or update the bitmask in *dumpSections according to arg.
38 * dumpSections is initialised as DUMP_UNSECTIONED by pg_dump and
39 * pg_restore so they can know if this has even been called.
44 /* if this is the first call, clear all the bits */
48 if (strcmp(
arg,
"pre-data") == 0)
50 else if (strcmp(
arg,
"data") == 0)
52 else if (strcmp(
arg,
"post-data") == 0)
63/* Register a callback to be run when exit_nicely is invoked. */
68 pg_fatal(
"out of on_exit_nicely slots");
75 * Run accumulated on_exit_nicely callbacks in reverse order and then exit
76 * without printing any message.
78 * If running in a parallel worker thread on Windows, we only exit the thread,
79 * not the whole process.
81 * Note that in parallel operation on Windows, the callback(s) will be run
82 * by each thread since the list state is necessarily shared by all threads;
83 * each callback must contain logic to ensure it does only what's appropriate
84 * for its thread. On Unix, callbacks are also run by each process, but only
85 * for callbacks established before we fork off the child processes. (It'd
86 * be cleaner to reset the list after fork(), and let each child establish
87 * its own callbacks; but then the behavior would be completely inconsistent
88 * between Windows and Unix. For now, just be sure to establish callbacks
89 * before forking to avoid inconsistency.)
101 if (parallel_init_done && GetCurrentThreadId() != mainThreadId)
#define pg_log_error(...)
#define pg_log_error_hint(...)
static int on_exit_nicely_index
void exit_nicely(int code)
static struct @36 on_exit_nicely_list[MAX_ON_EXIT_NICELY]
on_exit_nicely_callback function
#define MAX_ON_EXIT_NICELY
void set_dump_section(const char *arg, int *dumpSections)
void on_exit_nicely(on_exit_nicely_callback function, void *arg)
void(* on_exit_nicely_callback)(int code, void *arg)