Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 9 Nov 2014 20:08:44 +0000 (UTC)
From:      Josh Paetzel <jpaetzel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r274327 - in stable/10: etc/rc.d share/man/man5
Message-ID:  <201411092008.sA9K8i6J077923@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jpaetzel
Date: Sun Nov  9 20:08:43 2014
New Revision: 274327
URL: https://svnweb.freebsd.org/changeset/base/274327

Log:
  MFC: 258080
  
  Add support for multiple instances of ftp-proxy
  and pflog devices.
  
  PR:     conf/158171
  Submitted by:   Thomas Johnson <tom@claimlynx.com>

Modified:
  stable/10/etc/rc.d/ftp-proxy
  stable/10/etc/rc.d/pflog
  stable/10/share/man/man5/rc.conf.5
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/etc/rc.d/ftp-proxy
==============================================================================
--- stable/10/etc/rc.d/ftp-proxy	Sun Nov  9 20:04:29 2014	(r274326)
+++ stable/10/etc/rc.d/ftp-proxy	Sun Nov  9 20:08:43 2014	(r274327)
@@ -14,4 +14,62 @@ rcvar="ftpproxy_enable"
 command="/usr/sbin/ftp-proxy"
 
 load_rc_config $name
-run_rc_command "$1"
+
+#
+# manage_pid argument
+#	Create or remove a pidfile manually, for daemons that can't be bothered
+#	to do it themselves. Takes one argument, which is the argument provided
+#	to the rc script. The pidfile will be named /var/run/<$name>.pid,
+#	unless $pidfile is defined.
+#
+#	The method used to determine the pid is rather hacky; grep ps output to
+#	find '$procname|$command', then grep for ${name}_flags. If at all
+#	possible, use another method if at all possible, to avoid that dirty-
+#	code feeling.
+#
+manage_pid() {
+	local search_string ps_pid
+	case $1 in
+		*start)
+			cmd_string=`basename ${procname:-${command}}`
+			eval flag_string=\"\$${name}_flags\"
+			# Determine the pid.
+			ps_pid=`ps ax -o pid= -o command= | grep $cmd_string | grep -e "$flag_string" | grep -v grep | awk '{ print $1 }'`
+			# Write the pidfile depending on $pidfile status.
+			echo $ps_pid > ${pidfile:-"/var/run/$name.pid"}
+	       		;;
+		stop)
+	       		rm $pidfile
+	       		;;
+	esac
+}
+
+# Allow ftp-proxy to start up in two different ways. The typical behavior
+# is to start up one instance of ftp-proxy by setting ftpproxy_enable and
+# ftpproxy_flags. The alternate behavior allows multiple instances of ftp-
+# proxy to be started, allowing different types of proxy behavior. To use the
+# new behavior, a list of instances must be defined, and a list of flags for
+# each instance. For example, if we want to start two instances of ftp-proxy,
+# foo and bar, we would set the following vars.
+#	ftpproxy_enable="YES"
+#	ftpproxy_instances="foo bar"
+#	ftpproxy_foo="<arguments for foo>"
+#	ftpproxy_bar="<arguments for bar>"
+#
+# Starting more than one ftp-proxy?
+if [ "$ftpproxy_instances" ] && [ -n "${ftpproxy_instances}" ]; then
+	# Iterate through instance list.
+	for i in $ftpproxy_instances; do
+		#eval ftpproxy_${i}_flags=\$ftpproxy_${i}
+		#eval name=ftpproxy_${i}
+		# Set flags for this instance.
+		eval ftpproxy_flags=\$ftpproxy_${i}
+		# Define a unique pid file name.
+		pidfile="/var/run/ftp-proxy.$i.pid"
+		run_rc_command "$1"
+		manage_pid $1
+	done
+else
+	# Traditional single-instance behavior
+	run_rc_command "$1"
+fi

Modified: stable/10/etc/rc.d/pflog
==============================================================================
--- stable/10/etc/rc.d/pflog	Sun Nov  9 20:04:29 2014	(r274326)
+++ stable/10/etc/rc.d/pflog	Sun Nov  9 20:08:43 2014	(r274327)
@@ -24,25 +24,41 @@ pflog_prestart()
 {
 	load_kld pflog || return 1
 
-	# set pflog0 interface to up state
-	if ! ifconfig pflog0 up; then
-		warn 'could not bring up pflog0.'
+	# set pflog_dev interface to up state
+	if ! ifconfig $pflog_dev up; then
+		warn "could not bring up $pflog_dev."
 		return 1
 	fi
 
 	# prepare the command line for pflogd
-	rc_flags="-f $pflog_logfile $rc_flags"
+	rc_flags="-f $pflog_logfile -i $pflog_dev $rc_flags"
 
 	# report we're ready to run pflogd
 	return 0
 }
 
+pflog_poststart() {
+	# Allow child pflogd to settle
+	sleep 0.10
+	# More elegant(?) method for getting a unique pid
+	if [ -f /var/run/pflogd.pid ]; then
+		mv /var/run/pflogd.pid $pidfile
+	else
+		warn "/var/run/pflogd.pid does not exist. Too fast."
+	fi
+}
+
 pflog_poststop()
 {
-	if ! ifconfig pflog0 down; then
-		warn 'could not bring down pflog0.'
+	if ! ifconfig $pflog_dev down; then
+		warn "could not bring down $pflog_dev."
 		return 1
 	fi
+
+	if [ "$pflog_instances" ] && [ -n "$pflog_instances" ]; then
+		rm $pidfile
+	fi
+
 	return 0
 }
 
@@ -53,4 +69,33 @@ pflog_resync()
 }
 
 load_rc_config $name
-run_rc_command "$1"
+
+# Check if spawning multiple pflogd
+echo "Starting pflogd: $pflog_instances"
+if [ "$pflog_instances" ] && [ -n "$pflog_instances" ]; then
+	start_postcmd="pflog_poststart"
+	# Interate through requested instances.
+	for i in $pflog_instances; do
+		# Set required variables
+		eval pflog_dev=\$pflog_${i}_dev
+		eval pflog_logfile=\$pflog_${i}_logfile
+		eval pflog_flags=\$pflog_${i}_flags
+		# Check that required vars have non-zero length, warn if not.
+		if [ -z $pflog_dev ]; then
+			warn "pflog_dev not set"
+			continue
+		fi
+		if [ -z $pflog_logfile ]; then
+			warn "pflog_logfile not set"
+			continue
+		fi
+		# pflogd sets a pidfile, but the name is hardcoded. Concoct a
+		# unique pidfile name.
+		pidfile="/var/run/pflogd.$i.pid"
+		run_rc_command "$1"
+	done
+else
+	# Typical case, spawn single instance only.
+	pflog_dev=${pflog_dev:-"pflog0"}
+	run_rc_command "$1"
+fi

Modified: stable/10/share/man/man5/rc.conf.5
==============================================================================
--- stable/10/share/man/man5/rc.conf.5	Sun Nov  9 20:04:29 2014	(r274326)
+++ stable/10/share/man/man5/rc.conf.5	Sun Nov  9 20:08:43 2014	(r274327)
@@ -936,6 +936,33 @@ Empty by default.
 This variable contains additional flags passed to the
 .Xr pflogd 8
 program.
+.It Va pflog_instances
+.Pq Vt str
+If logging to more than one 
+.Xr pflog 4
+interface is desired, 
+.Va pflog_instances
+is set to the list of
+.Xr pflogd 8
+instances that should be started at system boot time. If 
+.Va pflog_instances
+is set, for each whitespace-seperated
+.Ar element
+in the list,
+.Ao Ar element Ac Ns Va _dev
+and
+.Ao Ar element Ac Ns Va _logfile
+elements are assumed to exist.
+.Ao Ar element Ac Ns Va _dev
+must contain the
+.Xr pflog 4
+interface to be watched by the named
+.Xr pflogd 8
+instance.
+.Ao Ar element Ac Ns Va _logfile
+must contain the name of the logfile that will be used by the
+.Xr pflogd 8
+instance.
 .It Va ftpproxy_enable
 .Pq Vt bool
 Set to
@@ -954,6 +981,19 @@ Empty by default.
 This variable contains additional flags passed to the
 .Xr ftp-proxy 8
 program.
+.It Va ftpproxy_instances
+.Pq Vt str
+Empty by default. If multiple instances of
+.Xr ftp-proxy 8
+are desired at boot time, 
+.Va ftpproxy_instances
+should contain a whitespace-seperated list of instance names. For each
+.Ar element
+in the list, a variable named
+.Ao Ar element Ac Ns Va _flags
+should be defined, containing the command-line flags to be passed to the
+.Xr ftp-proxy 8
+instance.
 .It Va pfsync_enable
 .Pq Vt bool
 Set to



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201411092008.sA9K8i6J077923>