From b43915b38fbf9a2e8890794fe90405c5a75c612b Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Tue, 16 May 2023 22:34:40 -0700 Subject: [PATCH] runtests: handle interrupted reads from IPC pipes These can be interrupted by signals, especially SIGINT to shut down, and must be restarted so the IPC call arrives correctly. If the read just returns an error instead, the IPC calling state will go out of sync and a proper shutdown won't happen. Ref: #10818 --- tests/runner.pm | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/runner.pm b/tests/runner.pm index 879ed0e98c..89182004bf 100644 --- a/tests/runner.pm +++ b/tests/runner.pm @@ -1203,14 +1203,17 @@ sub controlleripccall { # Called by controller sub runnerar { my ($runnerid) = @_; + my $err; my $datalen; - if (sysread($controllerr{$runnerid}, $datalen, 4) <= 0) { - die "error in runnerar\n"; + while(! defined ($err = sysread($controllerr{$runnerid}, $datalen, 4)) || $err <= 0) { + $!{EINTR} || die "error in runnerar: $!\n"; + # system call was interrupted, probably by ^C; restart it so we stay in sync } my $len=unpack("L", $datalen); my $buf; - if (sysread($controllerr{$runnerid}, $buf, $len) <= 0) { - die "error in runnerar\n"; + while(! defined ($err = sysread($controllerr{$runnerid}, $buf, $len)) || $err <= 0) { + $!{EINTR} || die "error in runnerar: $!\n"; + # system call was interrupted, probably by ^C; restart it so we stay in sync } # Decode response values @@ -1259,14 +1262,17 @@ sub runnerar_ready { # The IPC is read from the $runnerr pipe and the response is # written to the $runnerw pipe sub ipcrecv { + my $err; my $datalen; - if (sysread($runnerr, $datalen, 4) <= 0) { - die "error in ipcrecv\n"; + while(! defined ($err = sysread($runnerr, $datalen, 4)) || $err <= 0) { + $!{EINTR} || die "error in ipcrecv: $!\n"; + # system call was interrupted, probably by ^C; restart it so we stay in sync } my $len=unpack("L", $datalen); my $buf; - if (sysread($runnerr, $buf, $len) <= 0) { - die "error in ipcrecv\n"; + while(! defined ($err = sysread($runnerr, $buf, $len)) || $err <= 0) { + $!{EINTR} || die "error in ipcrecv: $!\n"; + # system call was interrupted, probably by ^C; restart it so we stay in sync } # Decode the function name and arguments -- 2.47.3