diff options
| author | Magnus Hagander | 2014-02-09 12:10:14 +0000 |
|---|---|---|
| committer | Magnus Hagander | 2014-02-12 17:45:18 +0000 |
| commit | 63ab2befe0d2332a5571f46c1a2c0af9447c6a4b (patch) | |
| tree | c4f88602bed8864d70a9cfbe80d51ad3c35f6e12 /src/bin/pg_basebackup/pg_basebackup.c | |
| parent | 1c9acd5c86a71b8ab73bc139eb5e0ad292b9a7d4 (diff) | |
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.
Diffstat (limited to 'src/bin/pg_basebackup/pg_basebackup.c')
| -rw-r--r-- | src/bin/pg_basebackup/pg_basebackup.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index a6e320c0f22..c27c6332ce7 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -76,6 +76,7 @@ static PQExpBuffer recoveryconfcontents = NULL; /* Function headers */ static void usage(void); +static void disconnect_and_exit(int code); static void verify_dir_is_empty_or_create(char *dirname); static void progress_report(int tablespacenum, const char *filename, bool force); @@ -88,6 +89,26 @@ static void BaseBackup(void); static bool reached_end_position(XLogRecPtr segendpos, uint32 timeline, 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 static const char * get_gz_error(gzFile gzf) |
