Make sure we can read /proc/1/root, otherwise do not execute chroot test.
authorMichael Prokop <mika@grml.org>
Sun, 26 Dec 2010 23:38:57 +0000 (00:38 +0100)
committerMichael Prokop <mika@grml.org>
Sun, 26 Dec 2010 23:40:03 +0000 (00:40 +0100)
policy-rc.d

index 3964dc5..8ba05a4 100755 (executable)
@@ -6,10 +6,15 @@
 # License:       This file is licensed under the GPL v2.
 ################################################################################
 
-# test for chroot
-if test "$(/usr/bin/stat -c "%d/%i" /)" != "$(/usr/bin/stat -Lc "%d/%i" /proc/1/root 2>/dev/null)" ; then
-   # notify invoke-rc.d that nothing should be done -- we are in a chroot
-   exit 101
+## test for chroot
+# make sure /proc/1/root can be read, if not either /proc is not mounted
+# or it is not executed with root permissions (and "sudo invoke-rc.d $service"
+# might fail), if so don't continue
+if [ -d /proc/1 ] && readlink -f /proc/1/root >/dev/null 2>&1; then
+  if test "$(/usr/bin/stat -c "%d/%i" /)" != "$(/usr/bin/stat -Lc "%d/%i" /proc/1/root 2>/dev/null)" ; then
+     # notify invoke-rc.d that nothing should be done -- we are in a chroot
+     exit 101
+  fi
 fi
 
 # read configuration file