From f2ca1972a5d6cb8e2359b4fb321b1f93895ef885 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Tue, 27 Dec 2011 03:25:00 +0100 Subject: [PATCH] Example client: GNU Screen needs explicit locking --- client/example.pl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/example.pl b/client/example.pl index 954d446..a216647 100755 --- a/client/example.pl +++ b/client/example.pl @@ -86,8 +86,15 @@ sub tick($$) { my $g = 1 + int rand(2); print "[ii] bred $id ($g)\n"; #open LOG, ">>bred.log"; print LOG "$state->{agent_id} -> $id ($g)\n"; close LOG; + + # GNU screen is severly broken and will silently fail + # to spawn in case of a race. + use Time::HiRes; + while (!mkdir("_screen_excl")) { Time::HiRes::usleep(5000); } + # The child will remove _screen_excl. #system("screen sh -c './$0 $remote_port $id $g; read x'"); system("screen ./$0 $remote_port $id $g"); + $state->{last_bred} = $value; } elsif ($type eq 'agent_id') { @@ -291,6 +298,7 @@ if ($bred or not $agentid) { } print $socket "\r\n"; print "[ii] agent created\r\n"; +rmdir "_screen_excl"; # Start tick loop