Author: dougb
Date: Fri Apr 29 20:44:39 2011
New Revision: 221222
URL: http://svn.freebsd.org/changeset/base/221222

Log:
  MFC r216744 for rc.d/devd:
  
  Add pidfile [1]
  
  While I'm here, don't run the sysctl frob unconditionally, and
  s/sysctl/$SYSCTL/
  
  MFC r220962:
  
  Introduce to rc.subr get_pidfile_from_conf(). It does just what it sounds
  like, determines the path to a pid file as it is specified in a conf file.
  
  Use the new feature for rc.d/named and rc.d/devd, the 2 services in the
  base that list their pid files in their conf files.
  
  Remove the now-obsolete named_pidfile, and warn users if they have it set.
  
  MFC r220963:
  
  Improve the error handling for the new get_pidfile_from_conf()

Modified:
  stable/7/etc/defaults/rc.conf
  stable/7/etc/rc.d/devd
  stable/7/etc/rc.d/named
  stable/7/etc/rc.subr
Directory Properties:
  stable/7/etc/   (props changed)

Modified: stable/7/etc/defaults/rc.conf
==============================================================================
--- stable/7/etc/defaults/rc.conf       Fri Apr 29 20:31:52 2011        
(r221221)
+++ stable/7/etc/defaults/rc.conf       Fri Apr 29 20:44:39 2011        
(r221222)
@@ -247,7 +247,6 @@ named_enable="NO"           # Run named, the DNS 
 named_program="/usr/sbin/named" # Path to named, if you want a different one.
 named_conf="/etc/namedb/named.conf"    # Path to the configuration file
 #named_flags=""                        # Use this for flags OTHER than -u and 
-c
-named_pidfile="/var/run/named/pid" # Must set this in named.conf as well
 named_uid="bind"               # User to run named as
 named_chrootdir="/var/named"   # Chroot directory (or "" not to auto-chroot it)
 named_chroot_autoupdate="YES"  # Automatically install/update chrooted

Modified: stable/7/etc/rc.d/devd
==============================================================================
--- stable/7/etc/rc.d/devd      Fri Apr 29 20:31:52 2011        (r221221)
+++ stable/7/etc/rc.d/devd      Fri Apr 29 20:44:39 2011        (r221222)
@@ -14,10 +14,27 @@ name="devd"
 rcvar=`set_rcvar`
 command="/sbin/${name}"
 
+start_precmd=${name}_prestart
+stop_precmd=find_pidfile
+
+find_pidfile()
+{
+       if get_pidfile_from_conf pid-file /etc/devd.conf; then
+               pidfile="$_pidfile_from_conf"
+       else
+               pidfile="/var/run/${name}.pid"
+       fi
+}
+
+devd_prestart ()
+{
+       find_pidfile
+
+       # If devd is disabled, turn it off in the kernel to avoid memory leaks.
+       if ! checkyesno ${rcvar}; then
+           $SYSCTL hw.bus.devctl_disable=1
+       fi
+}
+
 load_rc_config $name
 run_rc_command "$1"
-
-# If devd is disabled, turn it off in the kernel to avoid memory leaks.
-if ! checkyesno ${rcvar}; then
-    sysctl hw.bus.devctl_disable=1
-fi

Modified: stable/7/etc/rc.d/named
==============================================================================
--- stable/7/etc/rc.d/named     Fri Apr 29 20:31:52 2011        (r221221)
+++ stable/7/etc/rc.d/named     Fri Apr 29 20:44:39 2011        (r221222)
@@ -112,8 +112,19 @@ named_reload()
        ${command%/named}/rndc reload
 }
 
+find_pidfile()
+{
+       if get_pidfile_from_conf pid-file $named_conf; then
+               pidfile="$_pidfile_from_conf"
+       else
+               pidfile="/var/run/named/pid"
+       fi
+}
+
 named_stop()
 {
+       find_pidfile
+
        # This duplicates an undesirably large amount of code from the stop
        # routine in rc.subr in order to use rndc to shut down the process,
        # and to give it a second chance in case rndc fails.
@@ -156,6 +167,12 @@ create_file () {
 
 named_prestart()
 {
+       find_pidfile
+
+       if [ -n "$named_pidfile" ]; then
+               warn 'named_pidfile: now determined from the conf file'
+       fi
+
        command_args="-u ${named_uid:=root}"
 
        if [ ! "$named_conf" = '/etc/namedb/named.conf' ]; then
@@ -279,7 +296,6 @@ load_rc_config $name
 #
 required_dirs="$named_chrootdir"       # if it is set, it must exist
 
-pidfile="${named_pidfile:-/var/run/named/pid}"
 named_confdir="${named_chrootdir}${named_conf%/*}"
 
 run_rc_command "$1"

Modified: stable/7/etc/rc.subr
==============================================================================
--- stable/7/etc/rc.subr        Fri Apr 29 20:31:52 2011        (r221221)
+++ stable/7/etc/rc.subr        Fri Apr 29 20:44:39 2011        (r221222)
@@ -372,6 +372,48 @@ 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}"
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to