Commit 16fda4b8 authored by Tom Lane's avatar Tom Lane

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.
parent ade2d61e
...@@ -290,7 +290,7 @@ reap_child(bool wait_for_child) ...@@ -290,7 +290,7 @@ reap_child(bool wait_for_child)
{ {
#ifndef WIN32 #ifndef WIN32
int work_status; int work_status;
int ret; pid_t child;
#else #else
int thread_num; int thread_num;
DWORD res; DWORD res;
...@@ -300,14 +300,13 @@ reap_child(bool wait_for_child) ...@@ -300,14 +300,13 @@ reap_child(bool wait_for_child)
return false; return false;
#ifndef WIN32 #ifndef WIN32
ret = waitpid(-1, &work_status, wait_for_child ? 0 : WNOHANG); child = waitpid(-1, &work_status, wait_for_child ? 0 : WNOHANG);
if (child == (pid_t) -1)
/* no children or, for WNOHANG, no dead children */ pg_fatal("waitpid() failed: %s\n", strerror(errno));
if (ret <= 0 || !WIFEXITED(work_status)) if (child == 0)
return false; return false; /* no children, or no dead children */
if (work_status != 0)
if (WEXITSTATUS(work_status) != 0) pg_fatal("child process exited abnormally: status %d\n", work_status);
pg_fatal("child worker exited abnormally: %s\n", strerror(errno));
#else #else
/* wait for one to finish */ /* wait for one to finish */
thread_num = WaitForMultipleObjects(parallel_jobs, thread_handles, thread_num = WaitForMultipleObjects(parallel_jobs, thread_handles,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment