blob: 182ebff2b8e09183e9053f328e1657db46d3e6cd [file] [log] [blame]
Pau Espin Pedrolfd4c1442018-10-25 17:37:23 +02001#!/bin/bash
2netns="$1"
3shift
Pau Espin Pedrole159cd22019-04-03 17:53:54 +02004
5child_ps=0
6forward_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}
16forward_kill_int() {
17 forward_kill "INT"
18}
19forward_kill_term() {
20 forward_kill "TERM"
21}
22forward_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!
28trap forward_kill_int INT
29trap forward_kill_term TERM
30trap forward_kill_usr1 USR1
31
Pau Espin Pedrolfd4c1442018-10-25 17:37:23 +020032#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 Pedrole159cd22019-04-03 17:53:54 +020033ip netns exec $netns "$@" &
34child_ps=$!
35
36echo "$$: waiting for $child_ps"
37wait "$child_ps"
38child_exit_code="$?"
39echo "child exited with $child_exit_code"
40
41exit $child_exit_code