Re: How to detect we are in a chroot? (was Re: Bug#543938: telinit: /etc/.initctl: ENOENT breaks debootstrap on kfreebsd)
On Thu, Aug 27, 2009 at 06:53:20PM +0200, Aurelien Jarno wrote:
> On Thu, Aug 27, 2009 at 04:54:47PM +0200, Philipp Kern wrote:
> > Package: libsepol1
> > Version: 2.0.37-2
> > Severity: important
> > I just tried to install kfreebsd-amd64 using d-i and debootstrap bailed
> > out due to libsepol1 failing to configure:
> > debootstrap: Setting up libsepol1 (2.0.37-2)
> > debootstrap: telinit:
> > debootstrap: /etc/.initctl: No such file or directory
> > debootstrap: dpkg: error processing libsepol1 (--configure):
> > debootstrap: subprocess installed post-installation script error exit status 1
> > I suspect that the recently uploaded version broke this.
> As discussed on IRC, that's due to the test:
> "$(stat -c %d/%i /)" = "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)"
> On GNU/kFreeBSD this test is always true. Any idea how to detect we are
> running on a chroot?
It looks like there are currently two main options:
- Using a sysctl CTL_KERN/KERN_PROC/KERN_PROC_FILEDESC and look for a -3
(KF_FD_TYPE_JAIL) descriptor. However this detect chroot / as a chroot
while we don't want that.
- Using libkvm it is possible to get the inode of the root directory and
detect if it is a chroot or not. Unfortunately root rights are needed.
Any other ideas?
Aurelien Jarno GPG: 1024D/F1BCDB73