Skip to content

Commit f7642cf

Browse files
committed
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.
1 parent cd24b4e commit f7642cf

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/bin/pg_upgrade/parallel.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ reap_child(bool wait_for_child)
294294
{
295295
#ifndef WIN32
296296
int work_status;
297-
int ret;
297+
pid_t child;
298298
#else
299299
int thread_num;
300300
DWORD res;
@@ -304,14 +304,13 @@ reap_child(bool wait_for_child)
304304
return false;
305305

306306
#ifndef WIN32
307-
ret = waitpid(-1, &work_status, wait_for_child ? 0 : WNOHANG);
308-
309-
/* no children or, for WNOHANG, no dead children */
310-
if (ret <= 0 || !WIFEXITED(work_status))
311-
return false;
312-
313-
if (WEXITSTATUS(work_status) != 0)
314-
pg_fatal("child worker exited abnormally: %s\n", strerror(errno));
307+
child = waitpid(-1, &work_status, wait_for_child ? 0 : WNOHANG);
308+
if (child == (pid_t) -1)
309+
pg_fatal("waitpid() failed: %s\n", strerror(errno));
310+
if (child == 0)
311+
return false; /* no children, or no dead children */
312+
if (work_status != 0)
313+
pg_fatal("child process exited abnormally: status %d\n", work_status);
315314
#else
316315
/* wait for one to finish */
317316
thread_num = WaitForMultipleObjects(parallel_jobs, thread_handles,

0 commit comments

Comments
 (0)