Pau Espin Pedrol | fd4c144 | 2018-10-25 17:37:23 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | netns="$1" |
| 3 | shift |
Pau Espin Pedrol | e159cd2 | 2019-04-03 17:53:54 +0200 | [diff] [blame] | 4 | |
| 5 | child_ps=0 |
| 6 | forward_kill() { |
| 7 | sig="$1" |
| 8 | echo "Caught signal SIG$sig!" |
| 9 | if [ "$child_ps" != "0" ]; then |
| 10 | echo "Killing $child_ps with SIG$sig!" |
| 11 | kill -SIG${sig} $child_ps |
| 12 | else |
| 13 | exit 0 |
| 14 | fi |
| 15 | } |
| 16 | forward_kill_int() { |
| 17 | forward_kill "INT" |
| 18 | } |
| 19 | forward_kill_term() { |
| 20 | forward_kill "TERM" |
| 21 | } |
| 22 | forward_kill_usr1() { |
| 23 | # Special signal received from osmo-gsm-tester to tell child to SIGKILL |
| 24 | echo "Converting SIGUSR1->SIGKILL" |
| 25 | forward_kill "KILL" |
| 26 | } |
| 27 | # Don't use 'set -e', otherwise traps are not triggered! |
| 28 | trap forward_kill_int INT |
| 29 | trap forward_kill_term TERM |
| 30 | trap forward_kill_usr1 USR1 |
| 31 | |
Pau Espin Pedrol | fd4c144 | 2018-10-25 17:37:23 +0200 | [diff] [blame] | 32 | #TODO: Later on I may want to call myself with specific ENV and calling sudo in order to run inside the netns but with dropped privileges |
Pau Espin Pedrol | e159cd2 | 2019-04-03 17:53:54 +0200 | [diff] [blame] | 33 | ip netns exec $netns "$@" & |
| 34 | child_ps=$! |
| 35 | |
| 36 | echo "$$: waiting for $child_ps" |
| 37 | wait "$child_ps" |
| 38 | child_exit_code="$?" |
| 39 | echo "child exited with $child_exit_code" |
| 40 | |
| 41 | exit $child_exit_code |