From 010b86413755ea59f099e230eb6590b875e787e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Boisnard?= Date: Wed, 16 Oct 2013 18:13:07 +0200 Subject: Allow concurent generation of XML routing files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BZ: 145938 XML generation is impossible when multiple instances of the script hostDomainGeneration are run (this is typically the case with the current Android Make process). This is because the way the ports used to communicate with test-platform and parameter-framework are chosen is not protected agains concurrent executions. This patch protects the initialization of the test-platform and parameter-framework agains concurrent executions using a flock. In particular, it ensures that the ports chosen are reserved to a specific process. Change-Id: I3d8fee2b20313814c79f5390851ad57dc696cc28 Signed-off-by: Frédéric Boisnard --- tools/xmlGenerator/hostDomainGenerator.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tools') diff --git a/tools/xmlGenerator/hostDomainGenerator.sh b/tools/xmlGenerator/hostDomainGenerator.sh index 1d4d79b..c618f46 100755 --- a/tools/xmlGenerator/hostDomainGenerator.sh +++ b/tools/xmlGenerator/hostDomainGenerator.sh @@ -65,6 +65,7 @@ TargetRoot="$ANDROID_PRODUCT_OUT/system" # Global variables TPSocket=5003 PFWSocket=5000 +PFWStartTimeout=60 tmpFile=$(mktemp) testPlatformPID=0 @@ -82,6 +83,7 @@ export LD_LIBRARY_PATH="$HostRoot/lib:${LD_LIBRARY_PATH:-}" # Setup clean trap, it will be called automatically on exit clean_up () { status=$? + echo "Clean sub process: $testPlatformPID" test $testPlatformPID != 0 && kill $testPlatformPID 2>&1 rm "$tmpFile" @@ -140,7 +142,9 @@ initTestPlatform () { formatConfigFile "$1" >"$tmpFile" # Check port is free + echo "Checking port $TPSocket for TestPlatform" ! portIsInUse $TPSocket || return 4 + echo "Port $TPSocket is available for TestPlatform" # Start test platform $testPlatform "$tmpFile" $TPSocket 2>&5 & @@ -172,7 +176,9 @@ launchTestPlatform () { $TPSendCommand setFailureOnFailedSettingsLoad false # Check port is free + echo "Checking port $PFWSocket for PFW" ! portIsInUse $PFWSocket || return 5 + echo "Port $PFWSocket is available for PFW" $TPSendCommand start if ! retry "$remoteProcess $PFWHost $PFWSocket help" 2 0.1 @@ -215,8 +221,21 @@ deleteEscapedNewLines () { linkLibrary libremote-processor_host.so libremote-processor.so # Start test platform and the PFW +# +# Creation of a critical section to ensure that the startup of the PFW (involving +# sockets creation to communicate with the test platform and the PFW) is serialized +# between potential concurrent execution of this script +# +# Acquire an exclusive lock on the file descriptor 200 +exec 200>/var/lock/.hostDomainGenerator.lockfile +flock --timeout $PFWStartTimeout 200 + +# Start the pfw using different socket if it fails safeStartPFW +# Release the lock +flock --unlock 200 + PFWSendCommand="$remoteProcess $PFWHost $PFWSocket" $PFWSendCommand setTuningMode on -- cgit v1.1