]> git.pld-linux.org Git - packages/rc-scripts.git/blob - rc-scripts-chroot_safe.patch
- and btw: rel 12.2
[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,29 @@
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" = "/var/lib/named" ] || \
28 +                               [ "$rewt" = "$CHROOT_TO_DIR" ]; then
29 +                               filteredpids="$filteredpids $1"
30 +                       fi
31 +               fi
32 +               shift
33 +       done
34 +
35 +       echo $filteredpids
36 +}
37 +
38  # A function to find the pid of a program.
39  pidofproc() 
40  {
41 @@ -401,6 +425,7 @@
42         # First try "/var/run/*.pid" files
43         if [ -f /var/run/$1.pid ] ; then
44                 pid=$(head -1 /var/run/$1.pid)
45 +               pid=$(filterchrooted $pid)
46                 if [ -n "$pid" ] ; then
47                         echo $pid
48                         return 0
49 @@ -409,16 +434,17 @@
50  
51         # Next try "pidof"
52         pid=$(pidof -o $$ -o $PPID -o %PPID -x $1)
53 +       pid=$(filterchrooted $pid)
54         if [ -n "$pid" ] ; then
55                 echo $pid
56                 return 0
57         fi
58  
59          # Finally try to extract it from ps
60 -        ps ax | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
61 +        filterchrooted `ps ax | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
62                             { if ((prog == $5) || (("(" prog ")") == $5) ||
63                               (("[" prog "]") == $5) ||
64 -                           ((prog ":") == $5)) { print $1 ; exit 0 } }' $1
65 +                           ((prog ":") == $5)) { print $1 ; exit 0 } }' $1`
66  }
67  
68  status() 
69 @@ -434,6 +460,7 @@
70  
71         # First try "pidof"
72         pid=$(pidof -o $$ -o $PPID -o %PPID -x $daemon)
73 +       pid=$(filterchrooted $pid)
74         if [ -n "$pid" ] ; then
75                 nls "%s (pid %s) is running..." "$daemon" "$pid"
76                 return 0
77 @@ -442,6 +469,7 @@
78                             { if ((prog == $5) || (("(" prog ")") == $5) ||
79                               (("[" prog "]") == $5) ||
80                             ((prog ":") == $5)) { print $1 ; exit 0 } }' $1`
81 +               pid=$(filterchrooted $pid)
82                  if [ "$pid" != "" ] ; then
83                          nls "%s (pid %s) is running..." "$daemon" "$pid"
84                          return 0
85 @@ -451,6 +479,7 @@
86         # Next try "/var/run/*.pid" files
87         if [ -f /var/run/$daemon.pid ] ; then
88                 pid=$(head -1 /var/run/$1.pid)
89 +               pid=$(filterchrooted $pid)
90                 if [ -n "$pid" ] ; then
91                         nls "%s dead but pid file exists" "$1"
92                         return 1
This page took 0.048721 seconds and 3 git commands to generate.