From a5d436672d2efb3717ced95a18dc20ecc6960c56 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Mon, 27 Dec 2010 00:38:57 +0100 Subject: [PATCH] Make sure we can read /proc/1/root, otherwise do not execute chroot test. --- policy-rc.d | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/policy-rc.d b/policy-rc.d index 3964dc5..8ba05a4 100755 --- a/policy-rc.d +++ b/policy-rc.d @@ -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 -- 2.1.4