changeset 405:b15809a0af09

Update run-with-distcc.sh to reliably kill distccd daemon on exit (even if killed by a signal), and vary port number so multiple targets can run in parallel.
author Rob Landley <rob@landley.net>
date Wed, 08 Oct 2008 00:01:21 -0500
parents ce5ba034d101
children 763712cce21f
files sources/toys/run-with-distcc.sh
diffstat 1 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/sources/toys/run-with-distcc.sh	Tue Oct 07 22:37:06 2008 -0500
+++ b/sources/toys/run-with-distcc.sh	Wed Oct 08 00:01:21 2008 -0500
@@ -22,20 +22,32 @@
   exit 1
 fi
 
-PATH="$(readlink -f "$1/distcc")" "$DCC" --listen 127.0.0.1 --log-stderr \
-  --log-level error --daemon -a 127.0.0.1 --no-detach 2>distccd.log &
+function portno()
+{
+  START=8192
+  RANGE=$[$(awk '{print $1}' /proc/sys/net/ipv4/ip_local_port_range)-$START]
+  if [ $RANGE -lt 1 ]
+  then
+    START=$[$(awk '{print $2}' /proc/sys/net/ipv4/ip_local_port_range)]
+    RANGE=$[65535-$PORT]
+  fi
+  echo $[($$%$RANGE)+$START]
+}
+
+PORT=$(portno)
+PATH="$(readlink -f "$1/distcc")" "$DCC" --listen 127.0.0.1 --no-detach \
+  --log-file distccd.log --log-level warning --daemon -a 127.0.0.1 -p $PORT &
+# Cleanup afterwards: Kill child processes we started (I.E. distccd).
+trap "kill $(jobs -p)" EXIT
 
 # Prepare some environment variables for run-qemu.sh
 
 export DISTCC_PATH_PREFIX=/tools/distcc:
 CPUS=$[$(echo /sys/devices/system/cpu/cpu[0-9]* | wc -w)+1]
-export KERNEL_EXTRA="DISTCC_HOSTS=10.0.2.2 CPUS=$CPUS $KERNEL_EXTRA"
+export KERNEL_EXTRA="DISTCC_HOSTS=10.0.2.2:$PORT CPUS=$CPUS $KERNEL_EXTRA"
 
 # Hand off to run-with-home.sh in the directory this script's running from.
 
 "$(readlink -f "$(which $0)" | sed -e 's@\(.*/\).*@\1@')"run-with-home.sh
 
-# Cleanup afterwards: Kill child processes we started (I.E. distccd).
-
 echo
-kill `jobs -p`