Commit 253f44cb authored by Tudor Bosman's avatar Tudor Bosman Committed by Jordan DeLong

Fix small race in subprocess_test

Summary:
It is possible for subprocess_test_parent_death_helper's child to signal
the parent between the check for "caught" and the call to "pause()", and
therefore pause() blocks forever.

Test Plan: ran the test in a loop

Reviewed By: delong.j@fb.com

FB internal diff: D979872
parent 5675ef27
...@@ -40,30 +40,21 @@ DEFINE_bool(child, false, ""); ...@@ -40,30 +40,21 @@ DEFINE_bool(child, false, "");
namespace { namespace {
constexpr int kSignal = SIGUSR1; constexpr int kSignal = SIGUSR1;
volatile bool caught = false;
void signalHandler(int sig) {
if (sig != kSignal) {
abort();
}
caught = true;
}
} // namespace } // namespace
void runChild(const char* file) { void runChild(const char* file) {
struct sigaction sa; // Block SIGUSR1 so it's queued
sa.sa_handler = signalHandler; sigset_t sigs;
sigemptyset(&sa.sa_mask); CHECK_ERR(sigemptyset(&sigs));
sa.sa_flags = 0; CHECK_ERR(sigaddset(&sigs, kSignal));
CHECK_ERR(sigaction(kSignal, &sa, nullptr)); CHECK_ERR(sigprocmask(SIG_BLOCK, &sigs, nullptr));
// Kill the parent, wait for our signal. // Kill the parent, wait for our signal.
CHECK_ERR(kill(getppid(), SIGKILL)); CHECK_ERR(kill(getppid(), SIGKILL));
while (!caught) { int sig = 0;
pause(); CHECK_ERR(sigwait(&sigs, &sig));
} CHECK_EQ(sig, kSignal);
// Signal completion by creating the file // Signal completion by creating the file
CHECK_ERR(creat(file, 0600)); CHECK_ERR(creat(file, 0600));
......
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