View | Details | Raw Unified | Return to bug 248584 | Differences between
and this patch

Collapse All | Expand All

(-)head/libexec/rc/rc.d/btpand (+144 lines)
Line 0 Link Here
1
#! /bin/sh
2
#
3
# $FreeBSD$
4
#
5
6
# PROVIDE: btpand
7
# REQUIRE: FILESYSTEMS NETWORKING
8
# REQUIRE: netif bluetooth
9
# BEFORE:
10
# KEYWORD: shutdown
11
12
. /etc/rc.subr
13
. /etc/network.subr
14
15
name="btpand"
16
desc="Bluetooth PAN daemon"
17
rcvar="btpand_enable"
18
start_precmd="btpand_start_precmd"
19
stop_postcmd="btpand_stop_postcmd"
20
required_modules=""
21
required_vars=""
22
23
load_rc_config "${name}"
24
25
: ${btpand_enable="NO"}
26
: ${btpand_tapif="tap0"}
27
: ${btpand_device=""}
28
: ${btpand_service="PANU"}
29
: ${btpand_remote=""}
30
31
command="/usr/sbin/${name}"
32
pidfile="/var/run/${btpand_tapif}.pid"
33
34
btpand_start_precmd ()
35
{
36
	local -
37
	# tap(4): to keep configured addresses when btpand stopped
38
	${IFCONFIG_CMD} ${btpand_tapif} link0
39
}
40
41
btpand_stop_postcmd ()
42
{
43
	local -
44
	if [ -f "${pidfile}" ] ; then
45
		rm -f -- "${pidfile}"
46
	fi
47
}
48
49
btpand_setup_flags ()
50
{
51
	if ! ifexists ${btpand_tapif} ; then
52
		warn
53
		return 1
54
	fi
55
	btpand_flags="${btpand_flags:-}${btpand_tapif:+ -i ${btpand_tapif}}"
56
57
	btpand_flags="${btpand_flags:-}${btpand_device:+ -d ${btpand_device}}"
58
59
	case "${btpand_service}" in	# (
60
	[Nn][Aa][Pp])
61
		btpand_flags="${btpand_flags:-}${btpand_service:+ -s NAP}"
62
		;;	# (
63
	[Gg][Nn])
64
		btpand_flags="${btpand_flags:-}${btpand_service:+ -s GN}"
65
		;;	# (
66
	[Pp][Aa][Nn][Uu])
67
		btpand_flags="${btpand_flags:-}${btpand_service:+ -s PANU}"
68
		;;	# (
69
	*)
70
		warn "unsupported PAN service. use PANU."
71
		btpand_flags="${btpand_flags:-}${btpand_service:+ -s PANU}"
72
		;;
73
	esac
74
75
	# PANU client
76
	btpand_flags="${btpand_flags:-}${btpand_remote:+ -a ${btpand_remote}}"
77
}
78
79
btpand_run_rc_command_profile ()
80
{
81
	local -
82
	local command command_args pidfile rcvar
83
	local _rc_restart_done
84
	local btpand_flags
85
	local btpand_tapif btpand_device btpand_service
86
	local profile _return
87
88
	profile="$1"
89
	shift 1
90
91
	eval "rcvar=\"btpand_${profile}_enable\""
92
	eval "btpand_flags=\"\${btpand_${profile}_flags:-${btpand_flags}}\""
93
	eval "btpand_tapif=\"\${btpand_${profile}_tapif:-${btpand_tapif}}\""
94
	eval "btpand_device=\"\${btpand_${profile}_device:-${btpand_device}}\""
95
	eval "btpand_service=\"\${btpand_${profile}_service:-${btpand_service}}\""
96
	eval "btpand_remote=\"\${btpand_${profile}_remote:-${btpand_remote}}\""
97
	eval "pidfile=\"/var/run/${btpand_tapif}.pid\""
98
	eval "_rc_restart_done=\"\${_rc_restart_done_btpand_${profile}:-false}\""
99
100
	if ! btpand_setup_flags ; then
101
		return 1
102
	fi
103
104
	run_rc_command ${1+"$@"}
105
	_return="${?}"
106
107
	eval "_rc_restart_done_btpand_${profile}=\"\${_rc_restart_done:-false}\""
108
109
	return "${_return}"
110
}
111
112
if [ -n "${btpand_profiles}" ] ; then
113
	btpand_rc_arg="$1"
114
	if [ ${#} -gt 0 ] ; then
115
		shift 1
116
	fi
117
118
	btpand_profiles="$(echo ${btpand_profiles})"
119
	btpand_run_profiles=""
120
	if [ -n "$*" ] ; then
121
		for profile
122
		do
123
			case " ${btpand_profiles} " in	# (
124
			*" ${profile} "*)
125
				btpand_run_profiles="${btpand_run_profiles:+${btpand_run_profiles} }${profile}"
126
				;;
127
			esac
128
		done
129
	else
130
		btpand_run_profiles="${btpand_profiles}"
131
	fi
132
133
	for profile in ${btpand_run_profiles}
134
	do
135
		echo "===> btpand profile: ${profile}"
136
		btpand_run_rc_command_profile "${profile}" "${btpand_rc_arg}"
137
	done
138
else
139
	if ! btpand_setup_flags ; then
140
		return 1
141
	fi
142
143
	run_rc_command ${1+"$@"}
144
fi

Return to bug 248584