From 1e5e81774c6fd194d9f42cdfa9e873f0568f91dd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Arkadiusz=20Mi=C5=9Bkiewicz?= Date: Sat, 10 Jan 2004 13:42:43 +0000 Subject: [PATCH] Support for handling processes inside and outside of chrooted systems based on rc-scripts-chroot_safe.patch. svn-id: @3149 --- rc.d/init.d/functions | 29 ++++++++++++++++++++++++----- sysconfig/system | 4 ++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions index 0beb3e55..696ff645 100644 --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -323,6 +323,25 @@ checkpid() return 1 } +# outside chroot get only thsese processes which are outside chroot. +# inside chroot get only these processes which are inside of chroot. +# (note: some processes like named are chrooted but run outside chroot) +filter_chroot() +{ + [ $# -lt 1 ] && return + good_pids="" + for root_pid in $@; do + root_dir=$(resolvesymlink /proc/${root_pid}/root) + if [ -n "$root_dir" ]; then + for r_dir in ${SYSTEM_CHROOTS}; do + [ "$rewt" = "$CHROOT_TO_DIR" ] && good_pids="$good_pids $root_pid" + done + [ "$root_dir" = "/" -o "$root_dir" = "/usr/share/empty" ] && good_pids="$good_pids $root_pid" + fi + done + echo $good_pids +} + # Usage run_cmd Message command_to_run run_cmd() { @@ -521,14 +540,12 @@ pidofproc() for p in $line; do [ -z "$(echo "$p" | awk '{gsub(/[0-9]/,"");print;}')" ] && pid="$pid $p" done - if [ -n "$pid" ]; then - echo $pid - return 0 - fi fi # Next try "pidof" - pidof -o $$ -o $PPID -o %PPID -x "$1" + [ -z "$pid" ] && pidof -o $$ -o $PPID -o %PPID -x "$1" + pid=$(filter_chroot "$pid") + echo $pid } status() @@ -546,6 +563,7 @@ status() # First try "pidof" pid=$(pidof -o $$ -o $PPID -o %PPID -x $daemon) + pid=$(filter_chroot "$pid") if [ "$pid" != "" ]; then nls "%s (pid %s) is running..." "$daemon" "$pid" @@ -564,6 +582,7 @@ status() # Next try "/var/run/*.pid" files if [ -f /var/run/${base}.pid ]; then read pid < /var/run/${base}.pid + pid=$(filter_chroot "$pid") if [ "$pid" != "" ]; then nls "%s dead but pid file exists" "$subsys" return 1 diff --git a/sysconfig/system b/sysconfig/system index 71091fb2..616cc46e 100644 --- a/sysconfig/system +++ b/sysconfig/system @@ -88,5 +88,9 @@ EVMS_OS2=no # Set to anything other than 'no' to allow hotkey interactive startup... PROMPT=yes +# List of chroots separated by space (to handle processes inside/outsite +# chroot properly) +#SYSTEM_CHROOTS= + # This must be last line ! # vi:syntax=sh:tw=78:ts=8:sw=4 -- 2.44.0