Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0ae288d

Browse files
committed
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 (streamingxlog process) would stay around and keep streaming.
1 parentdd56051 commit0ae288d

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static volatile LONG has_xlogendptr = 0;
7272

7373
/* Function headers */
7474
staticvoidusage(void);
75+
staticvoiddisconnect_and_exit(intcode);
7576
staticvoidverify_dir_is_empty_or_create(char*dirname);
7677
staticvoidprogress_report(inttablespacenum,constchar*filename);
7778

@@ -82,6 +83,26 @@ static void BaseBackup(void);
8283
staticboolreached_end_position(XLogRecPtrsegendpos,uint32timeline,
8384
boolsegment_finished);
8485

86+
87+
staticvoiddisconnect_and_exit(intcode)
88+
{
89+
if (conn!=NULL)
90+
PQfinish(conn);
91+
92+
#ifndefWIN32
93+
/*
94+
* On windows, our background thread dies along with the process.
95+
* But on Unix, if we have started a subprocess, we want to kill
96+
* it off so it doesn't remain running trying to stream data.
97+
*/
98+
if (bgchild>0)
99+
kill(bgchild,SIGTERM);
100+
#endif
101+
102+
exit(code);
103+
}
104+
105+
85106
#ifdefHAVE_LIBZ
86107
staticconstchar*
87108
get_gz_error(gzFilegzf)

‎src/bin/pg_basebackup/pg_receivexlog.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ static void StreamLog();
5151
staticboolstop_streaming(XLogRecPtrsegendpos,uint32timeline,
5252
boolsegment_finished);
5353

54+
#definedisconnect_and_exit(code)\
55+
{\
56+
if (conn != NULL) PQfinish(conn);\
57+
exit(code);\
58+
}
59+
60+
5461
staticvoid
5562
usage(void)
5663
{

‎src/bin/pg_basebackup/streamutil.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ extern intdbgetpassword;
99
/* Connection kept global so we can disconnect easily */
1010
externPGconn*conn;
1111

12-
#definedisconnect_and_exit(code)\
13-
{\
14-
if (conn != NULL) PQfinish(conn);\
15-
exit(code);\
16-
}
17-
18-
1912
char*xstrdup(constchar*s);
2013
void*xmalloc0(intsize);
2114

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp