1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-03 20:02:46 +03:00

Kill pg_basebackup background process when exiting

If an error occurs in the foreground (backup) process of pg_basebackup,
and we exit in a controlled way, the background process (streaming
xlog process) would stay around and keep streaming.
This commit is contained in:
Magnus Hagander
2014-02-09 13:10:14 +01:00
parent dd56051040
commit 0ae288d2dd
3 changed files with 28 additions and 7 deletions

View File

@ -72,6 +72,7 @@ static volatile LONG has_xlogendptr = 0;
/* Function headers */ /* Function headers */
static void usage(void); static void usage(void);
static void disconnect_and_exit(int code);
static void verify_dir_is_empty_or_create(char *dirname); static void verify_dir_is_empty_or_create(char *dirname);
static void progress_report(int tablespacenum, const char *filename); static void progress_report(int tablespacenum, const char *filename);
@ -82,6 +83,26 @@ static void BaseBackup(void);
static bool reached_end_position(XLogRecPtr segendpos, uint32 timeline, static bool reached_end_position(XLogRecPtr segendpos, uint32 timeline,
bool segment_finished); bool segment_finished);
static void disconnect_and_exit(int code)
{
if (conn != NULL)
PQfinish(conn);
#ifndef WIN32
/*
* On windows, our background thread dies along with the process.
* But on Unix, if we have started a subprocess, we want to kill
* it off so it doesn't remain running trying to stream data.
*/
if (bgchild> 0)
kill(bgchild, SIGTERM);
#endif
exit(code);
}
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
static const char * static const char *
get_gz_error(gzFile gzf) get_gz_error(gzFile gzf)

View File

@ -51,6 +51,13 @@ static void StreamLog();
static bool stop_streaming(XLogRecPtr segendpos, uint32 timeline, static bool stop_streaming(XLogRecPtr segendpos, uint32 timeline,
bool segment_finished); bool segment_finished);
#define disconnect_and_exit(code) \
{ \
if (conn != NULL) PQfinish(conn); \
exit(code); \
}
static void static void
usage(void) usage(void)
{ {

View File

@ -9,13 +9,6 @@ extern int dbgetpassword;
/* Connection kept global so we can disconnect easily */ /* Connection kept global so we can disconnect easily */
extern PGconn *conn; extern PGconn *conn;
#define disconnect_and_exit(code) \
{ \
if (conn != NULL) PQfinish(conn); \
exit(code); \
}
char *xstrdup(const char *s); char *xstrdup(const char *s);
void *xmalloc0(int size); void *xmalloc0(int size);