#!/bin/sh

# PROVIDE: snmptrapd
# REQUIRE: DAEMON
#
# Add the following line to /etc/rc.conf to enable snmptrapd:
#
# snmptrapd_enable="YES"
#
# Add the following line to make snmptrapd run as root.  By default it drops
# privileges after initialization, but some configurations may require root
# privileges.
#
# snmptrapd_sugid="NO"
#

snmptrapd_enable=${snmptrapd_enable-"NO"}
snmptrapd_flags=${snmptrapd_flags-"-p /var/run/snmptrapd.pid"}
snmptrapd_sugid=${snmptrapd_sugid-"YES"}

. /etc/rc.subr

load_rc_config net_snmptrapd

if [ ! -z "$net_snmptrapd_enable" ]; then
	echo "Warning: \$net_snmptrapd_enable is obsolete."
	echo "         Use \$snmptrapd_enable instead."
	snmptrapd_enable="$net_snmptrapd_enable"
	[ ! -z "$net_snmptrapd_flags" ] && snmptrapd_flags="$net_snmptrapd_flags"
fi

name=snmptrapd
rcvar=snmptrapd_enable

command=%%PREFIX%%/sbin/${name}
pidfile=/var/run/${name}.pid

load_rc_config ${name}

start_precmd=snmptrapd_precmd

snmptrapd_precmd() {
	if checkyesno snmptrapd_sugid; then
		rc_flags="-u snmpd -g snmpd ${rc_flags}"
	fi
}

run_rc_command "$1"
