--- etc/rc.d/dhclient.orig 2011-10-26 19:15:02.000000000 +0400 +++ etc/rc.d/dhclient 2011-10-27 09:04:07.000000000 +0400 @@ -15,9 +15,21 @@ rcvar= pidfile="/var/run/${name}.${ifn}.pid" start_precmd="dhclient_prestart" +stop_precmd="dhclient_pre_check" + +# rc_force check can only be done at the run_rc_command +# time, so we're testing it in the pre* hooks. +dhclient_pre_check() +{ + if [ -z "${rc_force}" ] && ! dhcpif $ifn; then + err 1 "'$ifn' is not a DHCP-enabled interface" + fi +} dhclient_prestart() { + dhclient_pre_check + # Interface-specific flags (see rc.subr for $flags setting) specific=$(get_if_var $ifn dhclient_flags_IF) if [ -z "$flags" -a -n "$specific" ]; then @@ -38,11 +50,8 @@ if [ -z $ifn ] ; then # only complain if a command was specified but no interface if [ -n "$1" ] ; then - echo 1>&2 "$0: no interface specified" - return 1 + err 1 "$0: no interface specified" fi -elif [ -z "${rc_force}" ] && ! dhcpif $ifn; then - return 1 fi run_rc_command "$1"