Fix a time race in Time-HiRes/t/itimer.t test

This commit is contained in:
Petr Písař 2018-09-05 15:35:49 +02:00
parent e7f6de4785
commit e039a7964c
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,54 @@
From ecbf46993f6ffbdc255f6ded3c6c05a8266a71e8 Mon Sep 17 00:00:00 2001
From: David Mitchell <davem@iabyn.com>
Date: Tue, 7 Aug 2018 12:26:31 +0100
Subject: [PATCH] Time-HiRes/t/itimer.t: avoid race condition.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This test script sets a repeating interval timer going, and after 4
'ticks' (SIGVTALRM), disables the timer (by setting it to zero).
The main loop which does CPU burning, does a getitmer() every now and
again, and when the value is zero, assumes the signal handler has
disabled the timer, and so finishes.
The trouble was that it was checking the 'time left', which can reach
zero because the interval timer has counted down to zero, and the signal
handler is about to be called, but the interval hasn't been reset back
to 0.4s yet.
i.e. the code doesn't distinguish between "timer disabled" and "timer
just reached zero".
In that scenario, the cleanup code in the test script disables the
SIGVTALRM handler while the timer is still active, and so the process
gets killed if another signal is raised.
This commit changes the test to check the second value returned by
getitmer() for being zero rather than the first - the second being the
repeat interval, whichb is always 0.4 until the timer is disabled.
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
dist/Time-HiRes/t/itimer.t | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/dist/Time-HiRes/t/itimer.t b/dist/Time-HiRes/t/itimer.t
index e196b1648c..432b224488 100644
--- a/dist/Time-HiRes/t/itimer.t
+++ b/dist/Time-HiRes/t/itimer.t
@@ -51,7 +51,9 @@ ok(defined $virt && abs($virt / 0.5) - 1 < $limit,
printf("# getitimer: %s\n", join(" ",
Time::HiRes::getitimer(&Time::HiRes::ITIMER_VIRTUAL)));
-while (Time::HiRes::getitimer(&Time::HiRes::ITIMER_VIRTUAL)) {
+# burn CPU until the VTALRM signal handler sets the repeat interval to
+# zero, indicating that the timer has fired 4 times.
+while ((Time::HiRes::getitimer(&Time::HiRes::ITIMER_VIRTUAL))[1]) {
my $j;
for (1..1000) { $j++ } # Can't be unbreakable, must test getitimer().
}
--
2.14.4

View File

@ -187,6 +187,9 @@ Patch24: perl-5.29.0-Make-utf8_to_uvchr-safer.patch
Patch25: perl-5.29.0-Fix-VC6-build-following-commit-aa3c16bd70.patch
Patch26: perl-5.29.1-Make-utf8_to_uvchr-slightly-safer.patch
# Fix a time race in Time-HiRes/t/itimer.t test, in upstream after 5.29.1
Patch27: perl-5.29.1-Time-HiRes-t-itimer.t-avoid-race-condition.patch
# Link XS modules to libperl.so with EU::CBuilder on Linux, bug #960048
Patch200: perl-5.16.3-Link-XS-modules-to-libperl.so-with-EU-CBuilder-on-Li.patch
@ -2765,6 +2768,7 @@ Perl extension for Version Objects
%patch24 -p1
%patch25 -p1
%patch26 -p1
%patch27 -p1
%patch200 -p1
%patch201 -p1
@ -2798,6 +2802,7 @@ perl -x patchlevel.h \
'Fedora Patch24: Fix a buffer overrun in deprecated utf8_to_uvchr()' \
'Fedora Patch25: Fix a buffer overrun in deprecated utf8_to_uvchr()' \
'Fedora Patch26: Fix a buffer overrun in deprecated utf8_to_uvchr()' \
'Fedora Patch27: Fix a time race in Time-HiRes/t/itimer.t test' \
'Fedora Patch200: Link XS modules to libperl.so with EU::CBuilder on Linux' \
'Fedora Patch201: Link XS modules to libperl.so with EU::MM on Linux' \
%{nil}
@ -5089,6 +5094,7 @@ popd
* Wed Sep 05 2018 Petr Pisar <ppisar@redhat.com> - 4:5.28.0-421
- Fix a buffer overrun in deprecated S_is_utf8_common()
- Fix a buffer overrun in deprecated utf8_to_uvchr()
- Fix a time race in Time-HiRes/t/itimer.t test
* Wed Aug 01 2018 Petr Pisar <ppisar@redhat.com> - 4:5.28.0-420
- Fix a file descriptor leak in in-place edits (RT#133314)