Skip to content

Commit d2dad62

Browse files
author
Roy Sundahl
committed
Add wait for child processe(s) to exit. (amended+clang-formatted)
It was possible for the parent process to exit before the forked child process had finished. In some shells, this causes the pipe to close and FileCheck misses some output from the child. Waiting for the child process to exit before exiting the parent, assures that all output from stdout and stderr is combined and forwarded through the pipe to FileCheck. rdar://95241490 Differential Revision: https://reviews.llvm.org/D128565
1 parent 339e824 commit d2dad62

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

compiler-rt/test/asan/TestCases/Posix/coverage-fork.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <stdio.h>
1414
#include <string.h>
15+
#include <sys/wait.h>
1516
#include <unistd.h>
1617

1718
__attribute__((noinline))
@@ -32,6 +33,10 @@ int main(int argc, char **argv) {
3233
fprintf(stderr, "Parent PID: %d\n", getpid());
3334
foo();
3435
bar();
36+
37+
// Wait for the child process(s) to finish
38+
while (wait(NULL) > 0)
39+
;
3540
}
3641
return 0;
3742
}

0 commit comments

Comments
 (0)