forked from ungleich-public/cdist
[explorer/machine_type] Implement chroot detection using /proc/.../mountinfo
This commit is contained in:
parent
5af1317c29
commit
05c2a62191
1 changed files with 43 additions and 21 deletions
|
@ -165,11 +165,21 @@ has_chroot_procfs() {
|
|||
test -d /proc/
|
||||
}
|
||||
|
||||
check_chroot_procfs() {
|
||||
check_chroot_procfs() (
|
||||
is_chroot=false # default
|
||||
if test -e /proc/1/root && ! files_same /proc/1/root /
|
||||
then
|
||||
is_chroot=true
|
||||
fi
|
||||
if test -e /proc/1/mountinfo -a -e /proc/self/mountinfo
|
||||
then
|
||||
has_mountinfo=true
|
||||
cmp -s /proc/1/mountinfo /proc/self/mountinfo || is_chroot=true
|
||||
fi
|
||||
|
||||
if ${is_chroot}
|
||||
then
|
||||
# try to determine where the chroot has been mounted
|
||||
(
|
||||
rootdev=$(LC_ALL=C df -P / | awk 'NR==2{print $1}')
|
||||
|
||||
if test -e "${rootdev}"
|
||||
|
@ -181,14 +191,26 @@ check_chroot_procfs() {
|
|||
# shellcheck disable=SC2012
|
||||
root_ino=$(ls -1di / | awk '{print $1}')
|
||||
|
||||
# Get mount point
|
||||
# escape chroot and find mount point by inode
|
||||
chroot /proc/1/root find "${rootdevmnt}" -xdev -type d -inum "${root_ino}"
|
||||
elif ${has_mountinfo}
|
||||
then
|
||||
while read -r mntid _ _ _ cmntpnt _
|
||||
do
|
||||
read -r _ _ _ _ hmntpnt _ <<-EOF
|
||||
$(grep -e "^$((mntid)) " /proc/1/mountinfo)
|
||||
EOF
|
||||
printf '%s\n' "${hmntpnt%${cmntpnt}}"
|
||||
done </proc/self/mountinfo \
|
||||
| sort -u \
|
||||
| head -n 1 # just take the first...
|
||||
fi
|
||||
)
|
||||
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
return 1
|
||||
}
|
||||
fi
|
||||
)
|
||||
|
||||
# Check for container
|
||||
|
||||
|
|
Loading…
Reference in a new issue