From 666e0028da02563bf4603e5d3e60e41c01a8e448 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Wed, 3 Jan 2007 14:38:03 +0000 Subject: Improved chroot detection, stolen from udev postinst. --- policy-rc.d | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'policy-rc.d') diff --git a/policy-rc.d b/policy-rc.d index bf0e993..8972383 100755 --- a/policy-rc.d +++ b/policy-rc.d @@ -1,6 +1,6 @@ #!/bin/sh -# $Id: policy-rc.d,v 1.3 2006-04-22 16:04:55 jonas Exp $ +# $Id: policy-rc.d,v 1.4 2007-01-03 14:38:03 jonas Exp $ # # Copyright © 2006 Jonas Smedegaard # Description: Suppress system V scripts if invoked within a chroot. @@ -26,6 +26,18 @@ TEMP=`getopt -s sh --long list,quiet -n "$PRG" -- "$@"` if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi eval set -- "$TEMP" +# Stolen from udev postinst +chrooted() { + if [ "$(stat -c %d/%i /)" = "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ]; + then + # the devicenumber/inode pair of / is the same as that of /sbin/init's + # root, so we're *not* in a chroot and hence return false. + return 1 + fi + echo "A chroot environment has been detected, udev not started." + return 0 +} + quiet="" list="" while true ; do @@ -55,7 +67,7 @@ EOF exit 0 fi -if [ ! -r /proc/1/root ]; then +if ! chrooted; then if ! [ "$quiet" ]; then echo >&2 "Chroot environment detected, suppressing sysV script." fi -- cgit v1.2.3