rc.subr: Add function to find scripts in local_startup directories
authorRobin Hahling <robin.hahling@gw-computing.net>
Sat, 22 Nov 2014 12:08:11 +0000 (13:08 +0100)
committerSascha Wildner <saw@online.de>
Sun, 23 Nov 2014 10:53:30 +0000 (11:53 +0100)
* Add 'find_local_scripts()' function which is useful for
service(8).

* Fix reference to function in service.sh. This fixes two issues in
  service(8) for which 'service -e' and 'service -l' would simply fail
  to list local startup scripts.

'find_local_scripts()' has been imported from FreeBSD, where it is
called 'find_local_scripts_new()'.

etc/rc.subr
usr.sbin/service/service.sh

index a8e8e44..1fe40b9 100644 (file)
@@ -1398,3 +1398,21 @@ devfs_domount()
 
 return 0
 }
+
+# Find scripts in local_startup directories.
+find_local_scripts() {
+       local_rc=''
+       for dir in ${local_startup}; do
+               if [ -d "${dir}" ]; then
+                       for file in `grep -l '^# PROVIDE:' ${dir}/* 2>/dev/null`; do
+                               case "$file" in
+                               *.sample) ;;
+                               *)      if [ -x "$file" ]; then
+                                               local_rc="${local_rc} ${file}"
+                                       fi
+                                       ;;
+                               esac
+                       done
+               fi
+       done
+}
index 71405b8..3ac91a5 100644 (file)
@@ -64,7 +64,7 @@ if [ -n "$RESTART" ]; then
        if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then
                skip="$skip -s nojail"
        fi
-       [ -n "$local_startup" ] && find_local_scripts_new
+       [ -n "$local_startup" ] && find_local_scripts
        files=`rcorder ${skip} ${local_rc} 2>/dev/null`
 
        for file in `reverse_list ${files}`; do
@@ -91,7 +91,7 @@ if [ -n "$ENABLED" -o -n "$RCORDER" ]; then
        if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then
                skip="$skip -s nojail"
        fi
-       [ -n "$local_startup" ] && find_local_scripts_new
+       [ -n "$local_startup" ] && find_local_scripts
        files=`rcorder ${skip} /etc/rc.d/* ${local_rc} 2>/dev/null`
 fi