From 15fc1d83d19f632823399eb450d35068fe2c0345 Mon Sep 17 00:00:00 2001 From: Tobias Werth Date: Mon, 6 Mar 2023 06:48:57 -0800 Subject: [PATCH] Handle `SIGWINCH` under `bazel run //some:test` (i.e. test rules) correctly. Previously, after two window resize events we would stop waiting for the child process. `wait` is interrupted by any trapped signal (and we trap all signals), so we need to call it in a loop until the child really exited. Fixes https://github.com/bazelbuild/bazel/issues/17215 Closes #17301. PiperOrigin-RevId: 514395755 Change-Id: Ifb763a55d53f230cde8b1ca77761d94ea6e43e1f --- tools/test/test-setup.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/test/test-setup.sh b/tools/test/test-setup.sh index 8529a88535ea61..b2912593d3d17b 100755 --- a/tools/test/test-setup.sh +++ b/tools/test/test-setup.sh @@ -352,13 +352,15 @@ cleanupPid=$! set +m +# Wait until $childPid fully exits. +# We need to wait in a loop because wait is interrupted by any incoming trapped +# signal (https://www.gnu.org/software/bash/manual/bash.html#Signals). +while kill -0 $childPid 2>/dev/null; do + wait $childPid +done +# Wait one more time to retrieve the exit code. wait $childPid -# If interrupted by a signal, use the signal as the exit code. But allow -# the child to actually finish from the signal we sent _it_ via signal_child. -# (Waiting on a stopped process is a no-op). -# Only once - if we receive multiple signals (of any sort), give up. exitCode=$? -wait $childPid # By this point, we have everything we're willing to wait for. Tidy up our own # processes and move on.