summaryrefslogtreecommitdiff
path: root/policy-rc.d
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2007-01-03 14:38:03 +0000
committerJonas Smedegaard <dr@jones.dk>2007-01-03 14:38:03 +0000
commit666e0028da02563bf4603e5d3e60e41c01a8e448 (patch)
tree6ce7e875331d77375f0aa361e73c2e236dc12ee8 /policy-rc.d
parent43e25445b94d27437819083188d6db663f932294 (diff)
Improved chroot detection, stolen from udev postinst.
Diffstat (limited to 'policy-rc.d')
-rwxr-xr-xpolicy-rc.d16
1 files changed, 14 insertions, 2 deletions
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 <dr@jones.dk>
# 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