From: Jarkko Hietaniemi Date: Sun, 25 May 2003 18:36:17 +0000 (+0000) Subject: Protect against race conditions: if the pid is not seen, X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=00c4b2c0ce2c4995f5fbe668570cff57bd4d2463;p=p5sagit%2Fp5-mst-13.2.git Protect against race conditions: if the pid is not seen, neither will be the $0 change be seen (and vice versa). p4raw-id: //depot/perl@19619 --- diff --git a/ext/threads/t/join.t b/ext/threads/t/join.t index 054d0fe..5ffc6c9 100644 --- a/ext/threads/t/join.t +++ b/ext/threads/t/join.t @@ -101,17 +101,24 @@ if ($^O eq 'linux') { # We parse ps output so this is OS-dependent. print "# mainthread: \$0 = $0\n"; print "# pid = $$\n"; if (open PS, "ps -f |") { # Note: must work in (all) Linux(es). - my $ok; + my ($sawpid, $sawexe); while () { s/\s+$//; # there seems to be extra whitespace at the end by ps(1)? print "# $_\n"; - if (/\b$$\b.+\bfoobar\b/) { - $ok++; + if (/^\S+\s+$$\s/) { + $sawpid++; + if (/\sfoobar\b/) { + $sawexe++; + } last; } } close PS; - ok($ok, 'altering $0 is effective'); + if ($sawpid) { + ok($sawpid && $sawexe, 'altering $0 is effective'); + } else { + skip("\$0 check: did not see pid $$ in 'ps -f |'"); + } } else { skip("\$0 check: opening 'ps -f |' failed: $!"); }