]> git.pld-linux.org Git - packages/rc-scripts.git/blob - rc-scripts-chroot_safe.patch
- typo
[packages/rc-scripts.git] / rc-scripts-chroot_safe.patch
1 --- ./rc.d/init.d/functions.orig        Tue Oct 29 18:08:50 2002
2 +++ ./rc.d/init.d/functions     Tue Oct 29 18:02:56 2002
3 @@ -9,6 +9,7 @@
4  #              Marek Obuchowicz <elephant@pld.org.pl>
5  #              Arkadiusz Mi¶kiewicz <misiek@pld.org.pl> 
6  #              Micha³ Kochanowicz <mkochano@pld.org.pl>
7 +#              Mariusz Mazur <mmazur@pld.org.pl>
8  
9  # First set up a default search path.
10  export PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
11 @@ -388,6 +389,28 @@
12         fi
13  }
14  
15 +# A function to filter out pids that are not in current chroot.
16 +
17 +filterchrooted()
18 +{
19 +       # We don't test syntax since we can get zero parameters
20 +
21 +       # Main loop.
22 +       while [ $# -gt 0 ]; do
23 +               rewt=$(resolvesymlink /proc/$1/root)
24 +               if [ -n "$rewt" ]; then
25 +                       if [ "$rewt" = "/" ] || \
26 +                               [ "$rewt" = "/usr/share/empty" ] || \
27 +                               [ "$rewt" = "$CHROOT_TO_DIR" ]; then
28 +                               filteredpids="$filteredpids $1"
29 +                       fi
30 +               fi
31 +               shift
32 +       done
33 +
34 +       echo $filteredpids
35 +}
36 +
37  # A function to find the pid of a program.
38  pidofproc() 
39  {
40 @@ -401,6 +425,7 @@
41         # First try "/var/run/*.pid" files
42         if [ -f /var/run/$1.pid ] ; then
43                 pid=$(head -1 /var/run/$1.pid)
44 +               pid=$(filterchrooted $pid)
45                 if [ -n "$pid" ] ; then
46                         echo $pid
47                         return 0
48 @@ -409,16 +434,17 @@
49  
50         # Next try "pidof"
51         pid=$(pidof -o $$ -o $PPID -o %PPID -x $1)
52 +       pid=$(filterchrooted $pid)
53         if [ -n "$pid" ] ; then
54                 echo $pid
55                 return 0
56         fi
57  
58          # Finally try to extract it from ps
59 -        ps ax | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
60 +        filterchrooted `ps ax | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
61                             { if ((prog == $5) || (("(" prog ")") == $5) ||
62                               (("[" prog "]") == $5) ||
63 -                           ((prog ":") == $5)) { print $1 ; exit 0 } }' $1
64 +                           ((prog ":") == $5)) { print $1 ; exit 0 } }' $1`
65  }
66  
67  status() 
68 @@ -434,6 +460,7 @@
69  
70         # First try "pidof"
71         pid=$(pidof -o $$ -o $PPID -o %PPID -x $daemon)
72 +       pid=$(filterchrooted $pid)
73         if [ -n "$pid" ] ; then
74                 nls "%s (pid %s) is running..." "$daemon" "$pid"
75                 return 0
76 @@ -442,6 +469,7 @@
77                             { if ((prog == $5) || (("(" prog ")") == $5) ||
78                               (("[" prog "]") == $5) ||
79                             ((prog ":") == $5)) { print $1 ; exit 0 } }' $1`
80 +               pid=$(filterchrooted $pid)
81                  if [ "$pid" != "" ] ; then
82                          nls "%s (pid %s) is running..." "$daemon" "$pid"
83                          return 0
84 @@ -451,6 +479,7 @@
85         # Next try "/var/run/*.pid" files
86         if [ -f /var/run/$daemon.pid ] ; then
87                 pid=$(head -1 /var/run/$1.pid)
88 +               pid=$(filterchrooted $pid)
89                 if [ -n "$pid" ] ; then
90                         nls "%s dead but pid file exists" "$1"
91                         return 1
This page took 0.031545 seconds and 3 git commands to generate.