ctdb-common: Avoid race between fd and signal events
authorAmitay Isaacs <amitay@samba.org>
Tue, 9 Apr 2019 04:44:04 +0000 (14:44 +1000)
committerAmitay Isaacs <amitay@samba.org>
Fri, 12 Apr 2019 08:19:29 +0000 (08:19 +0000)
commit289201277cd983b27cdfd5376c607eab112b4082
tree3c42066641fd58f05bbebe1e3face05691492b53
parent38dc6d11a26c2e9a2cae7927321f2216ceb1c5ec
ctdb-common: Avoid race between fd and signal events

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13895

In run_proc, there was an implicit assumption that when a process exits,
fd event (pipe between parent and child) would be processed first and
signal event (SIGCHLD for the child) would be processed later.

However, that is not the case.  SIGCHLD can be received asynchronously
any time even when the pipe data has not fully been read.  This causes
run_proc to miss some of the output from child process in tests.

When SIGCHLD is being processed, if the pipe between parent and child is
still open, then do an explict read from the pipe to ensure we read any
data still in the pipe before closing the pipe.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Autobuild-User(master): Amitay Isaacs <amitay@samba.org>
Autobuild-Date(master): Fri Apr 12 08:19:29 UTC 2019 on sn-devel-144
ctdb/common/run_proc.c