Avoid giving out bridges with broken tor versions.
[tor-bridgedb.git] / scripts / executioner
blob085b74debc5fca086315b4e36d8b0536bc728bf9
1 #!/bin/bash
2 ##############################################################################
4 # executioner
5 # -----------
6 # Run $@ for $1 seconds and then kill the process.
8 # :authors: Isis Agora Lovecruft, 0x2cdb8b35
9 # :date: 21 April 2013
10 # :version: 0.0.1
11 ##############################################################################
13 set -vx --
15 function killitwithfire () {
16 trap - ALRM
17 kill -ALRM $prog 2>/dev/null
18 kill -9 $! 2>/dev/null && exit 0
21 function waitforit () {
22 trap "killitwithfire" ALRM
23 sleep $1& wait
24 kill -ALRM $$
27 waitforit $1& prog=$! ; shift ;
28 trap "killitwithfire" ALRM INT
29 "$@"& wait $!
30 RET=$?
31 if [[ "$(ps -ef | awk -v pid=$prog '$2==pid{print}{}')" != "" ]]; then
32 kill -ALRM $prog
33 wait $prog
35 exit $RET