aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-12-16 14:51:47 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2018-12-16 14:51:47 -0500
commitf4290113f50d1bcd67a9e51b74927c59592ad2ea (patch)
tree8c10c6a0ea564243b6c0d6847d15615bcd2f6a63 /src
parent34010ac2fa187ce032a7b243c829c7ef5f047e20 (diff)
downloadpostgresql-f4290113f50d1bcd67a9e51b74927c59592ad2ea.tar.gz
postgresql-f4290113f50d1bcd67a9e51b74927c59592ad2ea.zip
Make error handling in parallel pg_upgrade less bogus.
reap_child() basically ignored the possibility of either an error in waitpid() itself or a child process failure on signal. We don't really need to do more than report and crash hard, but proceeding as though nothing is wrong is definitely Not Acceptable. The error report for nonzero child exit status was pretty off-point, as well. Noted while fooling around with child-process failure detection logic elsewhere. It's been like this a long time, so back-patch to all supported branches.
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_upgrade/parallel.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/bin/pg_upgrade/parallel.c b/src/bin/pg_upgrade/parallel.c
index 45540d5ce06..20d55729453 100644
--- a/src/bin/pg_upgrade/parallel.c
+++ b/src/bin/pg_upgrade/parallel.c
@@ -290,7 +290,7 @@ reap_child(bool wait_for_child)
{
#ifndef WIN32
int work_status;
- int ret;
+ pid_t child;
#else
int thread_num;
DWORD res;
@@ -300,14 +300,13 @@ reap_child(bool wait_for_child)
return false;
#ifndef WIN32
- ret = waitpid(-1, &work_status, wait_for_child ? 0 : WNOHANG);
-
- /* no children or, for WNOHANG, no dead children */
- if (ret <= 0 || !WIFEXITED(work_status))
- return false;
-
- if (WEXITSTATUS(work_status) != 0)
- pg_fatal("child worker exited abnormally: %s\n", strerror(errno));
+ child = waitpid(-1, &work_status, wait_for_child ? 0 : WNOHANG);
+ if (child == (pid_t) -1)
+ pg_fatal("waitpid() failed: %s\n", strerror(errno));
+ if (child == 0)
+ return false; /* no children, or no dead children */
+ if (work_status != 0)
+ pg_fatal("child process exited abnormally: status %d\n", work_status);
#else
/* wait for one to finish */
thread_num = WaitForMultipleObjects(parallel_jobs, thread_handles,