~ubuntu-branches/ubuntu/saucy/autofs/saucy-proposed

« back to all changes in this revision

Viewing changes to debian/patches/009_improved_init_script

  • Committer: Bazaar Package Importer
  • Author(s): Steinar H. Gunderson
  • Date: 2005-05-13 13:39:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050513133952-teczxws3qt5wo40h
Tags: 4.1.3+4.1.4beta2-10
062_fix_memory_leak: Fix a memory leak in 060_non_replicated_ping.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
diff -ruN -x Makefile.in -x configure autofs-4.0.0pre10.orig/samples/rc.autofs.in autofs-4.0.0pre10/samples/rc.autofs.in
2
 
--- autofs-4.0.0pre10.orig/samples/rc.autofs.in Tue Mar 27 23:08:23 2001
3
 
+++ autofs-4.0.0pre10/samples/rc.autofs.in      Tue Oct 16 11:23:57 2001
4
 
@@ -76,55 +76,100 @@
5
 
 #
6
 
 function getmounts()
7
 
 {
8
 
-#
9
 
-# Check for local maps to be loaded
10
 
-#
11
 
-if [ -f /etc/auto.master ]
12
 
-then
13
 
-    cat /etc/auto.master | sed -e '/^#/d' -e '/^$/d'| (
14
 
-       while read dir map options
15
 
-       do
16
 
-           if [ ! -z "$dir" -a ! -z "$map" \
17
 
-                       -a x`echo "$map" | cut -c1` != 'x-' ]
18
 
-           then
19
 
-               map=`echo "/etc/$map" | sed -e 's:^/etc//:/:'`
20
 
-               options=`echo "$options" | sed -e 's/\(^\|[ \t]\)-/\1/g'`
21
 
-               if [ -x $map ]; then
22
 
-                   echo "$DAEMON $daemonoptions $dir program $map $options $localoptions"
23
 
-               elif [ -f $map ]; then
24
 
-                   echo "$DAEMON $daemonoptions $dir file $map $options $localoptions"
25
 
-               else
26
 
-                   echo "$DAEMON $daemonoptions $dir `basename $map` $options $localoptions"
27
 
-               fi
28
 
+    if ! getmounts_file /etc/auto.master; then
29
 
+       if ! getnismounts auto.master; then
30
 
+           echo "no autofs mounts configured!" 1>&2
31
 
+       fi
32
 
+    fi
33
 
+}
34
 
+
35
 
+function getmounts_file()
36
 
+{
37
 
+    #
38
 
+    # Check for local maps to be loaded
39
 
+    #
40
 
+    local map="$1"
41
 
+    shift
42
 
+    if [ -f "$map" ]
43
 
+    then
44
 
+       cat "$map" | sed -e '/^#/d' -e '/^$/d' | process_master_file "$@"
45
 
+    else
46
 
+       return 1
47
 
+    fi
48
 
+}
49
 
+
50
 
+function process_master_file()
51
 
+{
52
 
+    local line_options="$@" daemon_options
53
 
+    while read dir map options
54
 
+    do
55
 
+       options="$line_options $options"
56
 
+       case "$dir" in
57
 
+           +*) getnismounts "${dir/+/}" $map $options
58
 
+               continue;
59
 
+       esac
60
 
+       if [ ! -z "$dir" -a ! -z "$map" \
61
 
+               -a x`echo "$map" | cut -c1` != 'x-' ]
62
 
+       then
63
 
+           type=""
64
 
+           if [ -x $map ]; then
65
 
+               type=program
66
 
+           elif [ -f $map ]; then
67
 
+               type=file
68
 
+           elif [ x`echo "$map" | cut -c1` == 'x/' ]; then
69
 
+               # Starts with '/', thus a file, but doesn't exist
70
 
+               # so leave it out, leaving 'type=""' (hro)
71
 
+               type=""
72
 
+           elif [ -f /etc/$map ]; then
73
 
+               type=file
74
 
+               map=/etc/$map
75
 
+           elif [ $map == hesiod ]; then
76
 
+               type=hesiod
77
 
+               map=""
78
 
+           elif [ $map == ldap ]; then
79
 
+               type=ldap
80
 
+               map=""
81
 
+           else
82
 
+               case "$map" in
83
 
+                   !*) type=program map="${map/!/}";;
84
 
+                   *)  type=yp;;
85
 
+               esac
86
 
            fi
87
 
-       done
88
 
-    )
89
 
-fi
90
 
+           daemon_options=`munge_options daemon $daemonoptions $options`
91
 
+           options=`munge_options mount $options`
92
 
+
93
 
+           if [ "$type" ]; then
94
 
+               echo "$DAEMON $daemon_options -- $dir $type $map $localoptions $options"
95
 
+           fi
96
 
+       fi
97
 
+    done
98
 
+}
99
 
+
100
 
+function getnismounts()
101
 
+{
102
 
+    #
103
 
+    # Check for YellowPage maps to be loaded
104
 
+    #
105
 
+    local map="$1"
106
 
+    shift
107
 
+    if [ -e /usr/bin/ypcat ] && [ `ypcat -k "$map" 2>/dev/null | wc -l` -gt 0 ]
108
 
+    then
109
 
+       ypcat -k "$map" | process_master_file "$@"
110
 
+    else
111
 
+       return 1
112
 
+    fi
113
 
+}
114
 
 
115
 
 #
116
 
-# Check for YellowPage maps to be loaded
117
 
+# List active mounts
118
 
 #
119
 
-if [ -e /usr/bin/ypcat ] && [ `ypcat -k auto.master 2>/dev/null | wc -l` -gt 0 ]
120
 
-then
121
 
-    ypcat -k auto.master | (
122
 
-       while read dir map options
123
 
+function active()
124
 
+{
125
 
+    ps ax|grep "[0-9]:[0-9][0-9] $DAEMON " |
126
 
+       while read pid tt stat time command
127
 
        do
128
 
-           if [ ! -z "$dir" -a ! -z "$map" \
129
 
-                       -a x`echo "$map" | cut -c1` != 'x-' ]
130
 
-           then
131
 
-               map=`echo "$map" | sed -e 's/^auto_/auto./'`
132
 
-               if echo $options | grep -- '-t' >/dev/null 2>&1 ; then
133
 
-                   mountoptions="--timeout $(echo $options | \
134
 
-                     sed 's/^.*-t\(imeout\)*[ \t]*\([0-9][0-9]*\).*$/\2/g')"
135
 
-               fi
136
 
-                options=`echo "$options" | sed -e '
137
 
-                  s/--*t\(imeout\)*[ \t]*[0-9][0-9]*//g
138
 
-                  s/\(^\|[ \t]\)-/\1/g'`
139
 
-               echo "$DAEMON $daemonoptions $mountoptions $dir yp $map $options $localoptions"
140
 
-           fi
141
 
+           echo $command
142
 
        done
143
 
-    )
144
 
-fi
145
 
 }
146
 
 
147
 
 #
148
 
@@ -134,13 +179,49 @@
149
 
 {
150
 
        echo "Configured Mount Points:"
151
 
        echo "------------------------"
152
 
-       getmounts
153
 
+       getmounts | sed 's/ -- / /'
154
 
        echo ""
155
 
        echo "Active Mount Points:"
156
 
        echo "--------------------"
157
 
-       ps ax|grep "[0-9]:[0-9][0-9] automount " | (
158
 
-               while read pid tt stat time command; do echo $command; done
159
 
-       )
160
 
+       active
161
 
+}
162
 
+
163
 
+function munge_options()
164
 
+{
165
 
+       local which="$1"
166
 
+       shift
167
 
+       echo "$@" | awk -v which="$which" '
168
 
+BEGIN {
169
 
+       RS="[, \n-]"
170
 
+       FS="="
171
 
+       daemon_opts[ "timeout" ] = "timeout"
172
 
+       daemon_opts[ "t" ] = "timeout"
173
 
+}
174
 
+{
175
 
+       if ( $0 ~ /^$/ )
176
 
+               next
177
 
+       if ( $1 in daemon_opts ) {
178
 
+               daemon[ daemon_opts[ $1 ] ] = $2
179
 
+       } else {
180
 
+               mount[$0] = 1
181
 
+       }
182
 
+}
183
 
+END {
184
 
+       if ( which ~ "^daemon$" ) {
185
 
+               if ( "timeout" in daemon ) {
186
 
+                       printf "--timeout=%s\n", daemon["timeout"]
187
 
+               }
188
 
+       } else {
189
 
+               for ( a in mount ) {
190
 
+                       if ( length( out ) )
191
 
+                               out=out "," a
192
 
+                       else
193
 
+                               out=a
194
 
+               }
195
 
+               printf "%s\n", out
196
 
+       }
197
 
+}
198
 
+'
199
 
 }
200
 
 
201
 
 # return true if at least one pid is alive
202
 
@@ -172,7 +253,7 @@
203
 
        # Check if the automounter is already running?
204
 
        if [ ! -f /var/lock/subsys/autofs ]; then
205
 
            echo 'Starting automounter: '
206
 
-           getmounts | sh
207
 
+           getmounts | sed 's/ -- / /' | sh
208
 
            touch /var/lock/subsys/autofs
209
 
        fi
210
 
        ;;
211
 
@@ -189,7 +270,7 @@
212
 
            fi
213
 
            echo "Automounter not stopped yet: retrying... (attempt $count)"
214
 
        done
215
 
-       if [ $count -gt 1 -a $count -le 10 ]; then
216
 
+       if [ $count -gt 1 -a $count -le 5 ]; then
217
 
            echo "Automounter stopped"
218
 
        fi
219
 
        rm -f /var/lock/subsys/autofs
220
 
@@ -202,13 +283,13 @@
221
 
        echo "Checking for changes to /etc/auto.master ...."
222
 
         TMP1=`mktemp /tmp/autofs.XXXXXX` || { echo "could not make temp file" >& 2; exit 1; }
223
 
         TMP2=`mktemp /tmp/autofs.XXXXXX` || { echo "could not make temp file" >& 2; exit 1; }
224
 
-       getmounts >$TMP1
225
 
+       getmounts | sed 's/ -- / /' >$TMP1
226
 
        ps ax|grep "[0-9]:[0-9][0-9] $DAEMON " | (
227
 
            while read pid tt stat time command; do
228
 
                echo "$command" >>$TMP2
229
 
                if ! grep -q "^$command" $TMP2; then
230
 
                        while kill -USR2 $pid; do
231
 
-                           sleep 3
232
 
+                               sleep 3
233
 
                        done
234
 
                        echo "Stop $command"
235
 
                fi
236
 
@@ -225,8 +306,15 @@
237
 
   status)
238
 
        status
239
 
        ;;
240
 
+  getmounts)
241
 
+       getmounts
242
 
+       ;;
243
 
+  active)
244
 
+       active
245
 
+       ;;
246
 
+
247
 
   *)
248
 
-       echo "Usage: $initdir/autofs {start|stop|restart|reload|status}"
249
 
+       echo "Usage: $initdir/autofs {start|stop|restart|reload|status|getmounts|active}"
250
 
        exit 1
251
 
 esac
252
 
 }
253
 
@@ -241,25 +329,48 @@
254
 
 #
255
 
 case "$1" in
256
 
     start)
257
 
-       echo -n 'Starting automounter:'
258
 
+       echo -n 'Starting automounter: '
259
 
-       getmounts | while read cmd mnt rest
260
 
+       getmounts | while read cmd args
261
 
        do
262
 
+               opt=${args%%-- *}
263
 
+               rest=${args#*-- }
264
 
+               mnt=${rest%% *}
265
 
+               rest=${rest#* }
266
 
                echo -n " $mnt"
267
 
-               pidfile=/var/run/autofs`echo $mnt | sed 's/\//./'`.pid
268
 
+               if [ ! -d /var/run/autofs ]; then
269
 
+                       mkdir /var/run/autofs
270
 
+               fi
271
 
+               pidfile=/var/run/autofs/`echo $mnt | sed 's,_,__,g;s,/,_:,g'`.pid
272
 
                start-stop-daemon --start --pidfile $pidfile --quiet \
273
 
-                       --exec $DAEMON $daemonoptions -- $mnt $rest
274
 
+                       --exec $DAEMON -- $opt $mnt $rest
275
 
        done
276
 
-       echo "."
277
 
+       echo "done."
278
 
        ;;
279
 
     stop)
280
 
-       echo 'Stopping automounter.'
281
 
+       echo -n 'Stopping automounter: '
282
 
        start-stop-daemon --stop --quiet --signal USR2 --exec $DAEMON
283
 
+       for file in /var/run/autofs/*.pid
284
 
+       do
285
 
+           if [ -e "$file" ]
286
 
+           then
287
 
+               pid=`head -n 1 $file`
288
 
+               command=`tail -n 1 $file`
289
 
+               if [ -z "`ps --no-heading $pid`" ]
290
 
+               then
291
 
+                   echo -n "Stopped $pid($command) "
292
 
+                   rm -f $file
293
 
+               else
294
 
+                   echo -n "Couldn't stop $pid($command) "
295
 
+               fi
296
 
+           fi
297
 
+       done
298
 
+       echo "done."
299
 
        ;;
300
 
-    reload|restart)
301
 
+    reload)
302
 
-       echo "Reloading automounter: checking for changes ... "
303
 
+       echo -n "Reloading automounter: checking for changes ... "
304
 
        TMP=/var/run/autofs.tmp
305
 
-       getmounts >$TMP
306
 
-       for i in /var/run/autofs.*.pid
307
 
+       getmounts | sed 's/ -- / /' >$TMP
308
 
+       for i in /var/run/autofs/*.pid
309
 
        do
310
 
                pid=`head -n 1 $i 2>/dev/null`
311
 
                [ "$pid" = "" ] && continue
312
 
@@ -268,16 +378,28 @@
313
 
                then
314
 
-                       echo "Stopping automounter: $command"
315
 
+                       echo -n "Stopping automounter: $command"
316
 
                        kill -USR2 $pid
317
 
+                       rm -f $i
318
 
                fi
319
 
        done
320
 
+       echo "done."
321
 
        rm -f $TMP
322
 
        $thisscript start
323
 
        ;;
324
 
+    force-reload|restart)
325
 
+       $0 stop
326
 
+       $0 start
327
 
+       ;;
328
 
     status)
329
 
        status
330
 
        ;;
331
 
+    getmounts)
332
 
+       getmounts | sed 's/ -- / /'
333
 
+       ;;
334
 
+    active)
335
 
+       active
336
 
+       ;;
337
 
     *)
338
 
-       echo "Usage: $initdir/autofs {start|stop|restart|reload|status}" >&2
339
 
+       echo "Usage: $initdir/autofs {start|stop|restart|reload|force-reload|status|getmounts|active}" >&2
340
 
        exit 1
341
 
        ;;
342
 
 esac