xref: /dflybsd-src/etc/rc.d/dhclient (revision ab4c55c707dde5384d8a233485cc87b3ea249687)
1#!/bin/sh
2#
3# $NetBSD: dhclient,v 1.8 2002/03/22 04:33:58 thorpej Exp $
4# $FreeBSD: src/etc/rc.d/dhclient,v 1.20.2.4 2007/03/10 14:07:01 yar Exp $
5#
6
7# PROVIDE: dhclient
8# REQUIRE: FILESYSTEMS
9# KEYWORD: nojail nostart
10
11. /etc/rc.subr
12. /etc/network.subr
13
14name="dhclient"
15rcvar=
16start_precmd="dhclient_prestart"
17stop_precmd="dhclient_precheck"
18stop_cmd="dhclient_stop"
19
20ifn="$2"
21pidfile="/var/run/${name}.${ifn}.pid"
22
23# $rc_force check can only be done at the "run_rc_command" phase,
24# so we're testing it in the pre* hooks.
25dhclient_precheck()
26{
27	if [ -z "$rc_force" ] && ! dhcpif $ifn; then
28		local msg="'$ifn' is not a DHCP-enabled interface"
29		if [ -z "$rc_quiet" ]; then
30			info "$msg"
31		else
32			debug "$msg"
33		fi
34		exit 1
35	fi
36}
37
38dhclient_prestart()
39{
40	dhclient_precheck
41
42	# Override for $ifn specific flags (see rc.subr for $flags setting)
43	local specific=$(get_if_var $ifn dhclient_flags_IF)
44	if [ -z "$flags" -a -n "$specific" ]; then
45		rc_flags=$specific
46	fi
47
48	rc_flags="$rc_flags $ifn"
49}
50
51dhclient_stop()
52{
53	# Killing the pid couldn't stop the child processes, so use the
54	# "-w" option to let dhclient kill them.
55	${dhclient_program} -x $ifn
56}
57
58load_rc_config $name
59load_rc_config network
60
61# Only complain if a command was specified but no interface.
62if [ -n "$1" ] && [ -z "$ifn" ]; then
63	err 1 "no interface specified"
64fi
65
66run_rc_command "$1"
67