| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# Helper script. If you want a 2nd shell that communicates with the testenv DC |
| 4 |
# you can use the nsenter command to change the namespace you're in. However, |
| 5 |
# this command is a bit unwieldy and changes depending on the testenv PID. |
| 6 |
# We can generate a helper script on the fly that abstracts all this |
| 7 |
# complexity, allowing you to use the same, simple command to change the |
| 8 |
# namespace that you're in, e.g. |
| 9 |
# st/ad_dc/nsenter.sh |
| 10 |
|
| 11 |
pid=$1 |
| 12 |
exports_file=$2 |
| 13 |
|
| 14 |
# The basic command to enter the testenv's network namespace. |
| 15 |
# We enter the user namespace as well (as ourself, which is really the root |
| 16 |
# user for the namespace), otherwise we need sudo to make this work. |
| 17 |
nsenter_cmd="nsenter -t $pid --net --user --preserve-credentials" |
| 18 |
|
| 19 |
# By default, the nsenter command will just start a new shell in the namespace. |
| 20 |
# we use a wrapper helper script, which first loads all the environment |
| 21 |
# variables that are usually defined in selftest (and prints some basic help). |
| 22 |
helper_script="$(dirname $0)/nsenter-helper.sh $exports_file" |
| 23 |
|
| 24 |
# generate the dynamic script |
| 25 |
dyn_script="$(dirname $2)/nsenter.sh" |
| 26 |
echo "#!/bin/sh" >$dyn_script |
| 27 |
echo "$nsenter_cmd $helper_script" >>$dyn_script |
| 28 |
chmod 755 $dyn_script |
| 29 |
|
| 30 |
# return the script we created |
| 31 |
echo "$dyn_script" |