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.
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"
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"
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
30 # return the script we created