The current --wd=<dir> changes CWD to the path which is opened *before* nsenter calls setns(). It may be useful if you want to use in namespace something from your current namespace. In this case, the option --wd works like a "tunnel" between namespaces. For some other use-cases, this is useless and you want to be sure that CWD always points to the target namespace. For this purpose this patch implements --wdns <dir>. Example: Setup the namespaces: # unshare --mount # mount /dev/sdc /mnt/A # touch /mnt/A/fooooo # echo $$ 2425872 Enter the namespace from another session: # nsenter --all --target 2425872 --wd=/mnt/A ls -a . .. # nsenter --all --target 2425872 --wdns=/mnt/A ls -a . .. fooooo lost+found Fixes: https://github.com/util-linux/util-linux/issues/1500 Signed-off-by: Karel Zak <kzak@redhat.com>
65 lines
1.2 KiB
Text
65 lines
1.2 KiB
Text
_nsenter_module()
|
|
{
|
|
local cur prev OPTS
|
|
COMPREPLY=()
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
case $prev in
|
|
'-S'|'--uid')
|
|
COMPREPLY=( $(compgen -W "uid" -- $cur) )
|
|
return 0
|
|
;;
|
|
'-G'|'--gid')
|
|
COMPREPLY=( $(compgen -W "gid" -- $cur) )
|
|
return 0
|
|
;;
|
|
'-t'|'--target')
|
|
local PIDS
|
|
PIDS=$(cd /proc && echo [0-9]*)
|
|
COMPREPLY=( $(compgen -W "$PIDS" -- $cur) )
|
|
return 0
|
|
;;
|
|
'-h'|'--help'|'-V'|'--version')
|
|
return 0
|
|
;;
|
|
esac
|
|
case $cur in
|
|
'=')
|
|
# FIXME: --root and --wd should use get only
|
|
# directories as compgen output. If $cur is
|
|
# overwrote the same way as below in case segment
|
|
# for $prev the command-line will get mangled.
|
|
cur=${cur#=}
|
|
;;
|
|
-*)
|
|
OPTS="
|
|
--all
|
|
--target
|
|
--mount=
|
|
--uts=
|
|
--ipc=
|
|
--net=
|
|
--pid=
|
|
--cgroup=
|
|
--user=
|
|
--time=
|
|
--setuid
|
|
--setgid
|
|
--preserve-credentials
|
|
--root=
|
|
--wd=
|
|
--wdns=
|
|
--no-fork
|
|
--help
|
|
--version
|
|
"
|
|
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
|
|
return 0
|
|
;;
|
|
esac
|
|
local IFS=$'\n'
|
|
compopt -o filenames
|
|
COMPREPLY=( $(compgen -f -- $cur) )
|
|
return 0
|
|
}
|
|
complete -F _nsenter_module nsenter
|