From e3e76b426bb17428fe8e3d1bbce4fdaa4d79a9ee Mon Sep 17 00:00:00 2001 From: Tobias Werth Date: Tue, 24 Jan 2023 16:14:30 +0100 Subject: [PATCH] Handle SIGWINCH in bazel run correctly. Previously, after two window resize events we would stop waiting for the child process - this makes sense for other signals but not for SIGWINCH. Fixes https://github.com/bazelbuild/bazel/issues/17215 --- tools/test/test-setup.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tools/test/test-setup.sh b/tools/test/test-setup.sh index 8529a88535ea61..7ddbd10ad79a58 100755 --- a/tools/test/test-setup.sh +++ b/tools/test/test-setup.sh @@ -356,9 +356,25 @@ 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. +# Only once - if we receive multiple signals (except SIGWINCH), give up. +# SIGWINCH is special since it is sent for every window resize event. exitCode=$? -wait $childPid + +# This exitcode indicates that the child received a SIGWINCH (likely forwarded +# by us). +sigwinch_exit=$((128+$(kill -l SIGWINCH))) +only_sigwinch_exit=0 +if [ $exitCode == $sigwinch_exit ]; then + only_sigwinch_exit=1 +fi +while true; do + wait $childPid + curExitCode=$? + if [ $only_sigwinch_exit != 1 ] || [ $curExitCode != $sigwinch_exit ]; then + break + fi +done + # By this point, we have everything we're willing to wait for. Tidy up our own # processes and move on.