--- ./rc.d/init.d/functions.orig Tue Oct 29 18:08:50 2002 +++ ./rc.d/init.d/functions Tue Oct 29 18:02:56 2002 @@ -9,6 +9,7 @@ # Marek Obuchowicz # Arkadiusz Mi¶kiewicz # Michał Kochanowicz +# Mariusz Mazur # First set up a default search path. export PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin" @@ -388,6 +389,28 @@ fi } +# A function to filter out pids that are not in current chroot. + +filterchrooted() +{ + # We don't test syntax since we can get zero parameters + + # Main loop. + while [ $# -gt 0 ]; do + rewt=$(resolvesymlink /proc/$1/root) + if [ -n "$rewt" ]; then + if [ "$rewt" = "/" ] || \ + [ "$rewt" = "/usr/share/empty" ] || \ + [ "$rewt" = "$CHROOT_TO_DIR" ]; then + filteredpids="$filteredpids $1" + fi + fi + shift + done + + echo $filteredpids +} + # A function to find the pid of a program. pidofproc() { @@ -401,6 +425,7 @@ # First try "/var/run/*.pid" files if [ -f /var/run/$1.pid ] ; then pid=$(head -1 /var/run/$1.pid) + pid=$(filterchrooted $pid) if [ -n "$pid" ] ; then echo $pid return 0 @@ -409,16 +434,17 @@ # Next try "pidof" pid=$(pidof -o $$ -o $PPID -o %PPID -x $1) + pid=$(filterchrooted $pid) if [ -n "$pid" ] ; then echo $pid return 0 fi # Finally try to extract it from ps - ps ax | awk 'BEGIN { prog=ARGV[1]; ARGC=1 } + filterchrooted `ps ax | awk 'BEGIN { prog=ARGV[1]; ARGC=1 } { if ((prog == $5) || (("(" prog ")") == $5) || (("[" prog "]") == $5) || - ((prog ":") == $5)) { print $1 ; exit 0 } }' $1 + ((prog ":") == $5)) { print $1 ; exit 0 } }' $1` } status() @@ -434,6 +460,7 @@ # First try "pidof" pid=$(pidof -o $$ -o $PPID -o %PPID -x $daemon) + pid=$(filterchrooted $pid) if [ -n "$pid" ] ; then nls "%s (pid %s) is running..." "$daemon" "$pid" return 0 @@ -442,6 +469,7 @@ { if ((prog == $5) || (("(" prog ")") == $5) || (("[" prog "]") == $5) || ((prog ":") == $5)) { print $1 ; exit 0 } }' $1` + pid=$(filterchrooted $pid) if [ "$pid" != "" ] ; then nls "%s (pid %s) is running..." "$daemon" "$pid" return 0 @@ -451,6 +479,7 @@ # Next try "/var/run/*.pid" files if [ -f /var/run/$daemon.pid ] ; then pid=$(head -1 /var/run/$1.pid) + pid=$(filterchrooted $pid) if [ -n "$pid" ] ; then nls "%s dead but pid file exists" "$1" return 1