rc.subr: Add get_pidfile_from_conf (from FreeBSD).
authorSascha Wildner <saw@online.de>
Wed, 12 Mar 2014 20:00:40 +0000 (21:00 +0100)
committerSascha Wildner <saw@online.de>
Wed, 12 Mar 2014 20:00:40 +0000 (21:00 +0100)
etc/rc.subr

index 27e27ac..f8eb674 100644 (file)
@@ -1,6 +1,5 @@
 # $NetBSD: rc.subr,v 1.49 2002/05/21 12:31:01 lukem Exp $
 # $FreeBSD: src/etc/rc.subr,v 1.13 2003/06/09 17:31:06 mtm Exp $
-# $DragonFly: src/etc/rc.subr,v 1.15 2008/04/05 08:07:11 matthias Exp $
 #
 # Copyright (c) 1997-2002 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -419,6 +418,49 @@ wait_for_pids()
 }
 
 #
+# get_pidfile_from_conf string file
+#
+#      Takes a string to search for in the specified file.
+#      Ignores lines with traditional comment characters.
+#
+# Example:
+#
+# if get_pidfile_from_conf string file; then
+#      pidfile="$_pidfile_from_conf"
+# else
+#      pidfile='appropriate default'
+# fi
+#
+get_pidfile_from_conf()
+{
+       if [ -z "$1" -o -z "$2" ]; then
+               err 3 "USAGE: get_pidfile_from_conf string file ($name)"
+       fi
+
+       local string file line
+
+       string="$1" ; file="$2"
+
+       if [ ! -s "$file" ]; then
+               err 3 "get_pidfile_from_conf: $file does not exist ($name)"
+       fi
+
+       while read line; do
+               case "$line" in
+               *[#\;]*${string}*)      continue ;;
+               *${string}*)            break ;;
+               esac
+       done < $file
+
+       if [ -n "$line" ]; then
+               line=${line#*/}
+               _pidfile_from_conf="/${line%%[\"\;]*}"
+       else
+               return 1
+       fi
+}
+
+#
 # run_rc_command argument
 #      Search for argument in the list of supported commands, which is:
 #              "start stop restart rcvar status poll ${extra_commands}"