devd.conf revision 220168
120253Sjoerg# $FreeBSD: head/etc/devd.conf 220168 2011-03-30 18:35:02Z trasz $
220302Sjoerg#
320302Sjoerg# Refer to devd.conf(5) and devd(8) man pages for the details on how to
420253Sjoerg# run and configure devd.
520253Sjoerg#
620253Sjoerg
720253Sjoerg# NB: All regular expressions have an implicit ^$ around them.
820253Sjoerg# NB: device-name is shorthand for 'match device-name'
920302Sjoerg
1020253Sjoergoptions {
1120253Sjoerg	# Each directory directive adds a directory the list of directories
1220253Sjoerg	# that we scan for files.  Files are read-in in the order that they
1320253Sjoerg	# are returned from readdir(3).  The rule-sets are combined to
1420302Sjoerg	# create a DFA that's used to match events to actions.
1520253Sjoerg	directory "/etc/devd";
1620253Sjoerg	directory "/usr/local/etc/devd";
1720302Sjoerg	pid-file "/var/run/devd.pid";
1820253Sjoerg
1920253Sjoerg	# Setup some shorthand for regex that we use later in the file.
2020253Sjoerg	#XXX Yes, these are gross -- imp
2120253Sjoerg	set scsi-controller-regex
2220253Sjoerg		"(aac|adv|adw|aha|ahb|ahc|ahd|aic|amd|amr|asr|bt|ciss|ct|dpt|\
2320253Sjoerg		esp|ida|iir|ips|isp|mlx|mly|mpt|ncr|ncv|nsp|stg|sym|trm|wds)\
2420253Sjoerg		[0-9]+";
2544229Sdavidn};
2620253Sjoerg
2720253Sjoerg# Note that the attach/detach with the highest value wins, so that one can
2830259Scharnier# override these general rules.
2930259Scharnier
3050479Speter#
3130259Scharnier# Configure the interface on attach.  Due to a historical accident, this
3230259Scharnier# script is called pccard_ether.
33286201Sbapt#
34286201Sbapt# NB: DETACH events are ignored; the kernel should handle all cleanup
35286201Sbapt#     (routes, arp cache) if you need to do something beware of races
36286201Sbapt#     against immediate create of a device w/ the same name; e.g.
37286201Sbapt#	ifconfig bridge0 destroy; ifconfig bridge0 create
3830259Scharnier#
39286201Sbaptnotify 0 {
4030259Scharnier	match "system"		"IFNET";
41286982Sbapt	match "type"		"ATTACH";
4220253Sjoerg	action "/etc/pccard_ether $subsystem start";
43286201Sbapt};
44286201Sbapt
45286201Sbapt#
46286201Sbapt# Try to start dhclient on Ethernet like interfaces when the link comes
4730259Scharnier# up.  Only devices that are configured to support DHCP will actually
48286201Sbapt# run it.  No link down rule exists because dhclient automatically exits
49286201Sbapt# when the link goes down.
5020253Sjoerg#
51286201Sbaptnotify 0 {
52286201Sbapt	match "system"		"IFNET";
5320253Sjoerg	match "type"		"LINK_UP";
5420253Sjoerg	media-type		"ethernet";
55286201Sbapt	action "/etc/rc.d/dhclient quietstart $subsystem";
5620253Sjoerg};
5723318Sache
5822394Sdavidn#
5952512Sdavidn# Like Ethernet devices, but separate because
6024214Sache# they have a different media type.  We may want
61286196Sbapt# to exploit this later.
62286196Sbapt#
63286196Sbaptdetach 0 {
64286196Sbapt	media-type "802.11";
65286196Sbapt	action "/etc/pccard_ether $device-name stop";
66286196Sbapt};
67286196Sbaptattach 0 {
68286196Sbapt	media-type "802.11";
69286196Sbapt	action "/etc/pccard_ether $device-name start";
70286196Sbapt};
71286196Sbaptnotify 0 {
72286196Sbapt	match "system"		"IFNET";
73286196Sbapt	match "type"		"LINK_UP";
7420253Sjoerg	media-type		"802.11";
75286196Sbapt	action "/etc/rc.d/dhclient quietstart $subsystem";
76286196Sbapt};
77286196Sbapt
78286196Sbapt# An entry like this might be in a different file, but is included here
79286196Sbapt# as an example of how to override things.  Normally 'ed50' would match
80286196Sbapt# the above attach/detach stuff, but the value of 100 makes it
81286196Sbapt# hard wired to 1.2.3.4.
82286196Sbaptattach 100 {
83286196Sbapt	device-name "ed50";
84286196Sbapt	action "ifconfig $device-name inet 1.2.3.4 netmask 0xffff0000";
85286196Sbapt};
86286196Sbaptdetach 100 {
87286196Sbapt	device-name "ed50";
88283961Sbapt};
89286982Sbapt
90286982Sbapt# When a USB Bluetooth dongle appears activate it
91286982Sbaptattach 100 {
92286982Sbapt	device-name "ubt[0-9]+";
93286982Sbapt	action "/etc/rc.d/bluetooth quietstart $device-name";
94286982Sbapt};
95286982Sbaptdetach 100 {
96286982Sbapt	device-name "ubt[0-9]+";
97286982Sbapt	action "/etc/rc.d/bluetooth quietstop $device-name";
98286982Sbapt};
99286982Sbapt
100286982Sbapt# Firmware downloader for Atheros AR3011 based USB Bluetooth devices
101286982Sbapt#attach 100 {
102286982Sbapt#	match "vendor" "0x0cf3";
103286982Sbapt#	match "product" "0x3000";
104286982Sbapt#	action "sleep 2 && /usr/sbin/ath3kfw -d $device-name -f /usr/local/etc/ath3k-1.fw";
105286982Sbapt#};
106286982Sbapt
107286982Sbapt# When a USB keyboard arrives, attach it as the console keyboard.
108286982Sbaptattach 100 {
109286982Sbapt	device-name "ukbd0";
110286982Sbapt	action "/etc/rc.d/syscons setkeyboard /dev/ukbd0";
111286982Sbapt};
112286982Sbaptdetach 100 {
113286982Sbapt	device-name "ukbd0";
114286982Sbapt	action "/etc/rc.d/syscons setkeyboard /dev/kbd0";
115286982Sbapt};
116286982Sbapt
117286982Sbaptattach 100 {
118286982Sbapt	device-name "ums[0-9]+";
119286982Sbapt	action "/etc/rc.d/moused quietstart $device-name";
120286982Sbapt};
121286982Sbapt
122286982Sbaptdetach 100 {
123286982Sbapt        device-name "ums[0-9]+";
124286982Sbapt        action "/etc/rc.d/moused stop $device-name";
125286982Sbapt};
126286986Sbapt
127286982Sbapt# Firmware download into the ActiveWire board. After the firmware download is
128286982Sbapt# done the device detaches and reappears as something new and shiny
129286982Sbapt# automatically.
130286982Sbaptattach 100 {
131286982Sbapt	match "vendor"	"0x0854";
132286982Sbapt	match "product"	"0x0100";
133286982Sbapt	match "release"	"0x0000";
134286982Sbapt	action "/usr/local/bin/ezdownload -f /usr/local/share/usb/firmware/0854.0100.0_01.hex $device-name";
135286982Sbapt};
136286982Sbapt
137286982Sbapt# Firmware download for Entrega Serial DB25 adapter.
138286982Sbaptattach 100 {
139286982Sbapt	match "vendor"	"0x1645";
140286982Sbapt	match "product"	"0x8001";
141286982Sbapt	match "release"	"0x0101";
142286982Sbapt	action "if ! kldstat -n usio > /dev/null 2>&1 ; then kldload usio; fi; /usr/sbin/ezdownload -v -f /usr/share/usb/firmware/1645.8001.0101 /dev/$device-name";
143286982Sbapt};
144286982Sbapt
145286982Sbapt# This entry starts the ColdSync tool in daemon mode. Make sure you have an up
146286982Sbapt# to date /usr/local/etc/palms. We override the 'listen' settings for port and
147286982Sbapt# type in /usr/local/etc/coldsync.conf.
148286982Sbaptnotify 100 {
149286982Sbapt	match "system"		"USB";
150286982Sbapt	match "subsystem"	"DEVICE";
151286196Sbapt	match "type"		"ATTACH";
152286196Sbapt	match "vendor"		"0x082d";
153283961Sbapt	match "product"		"0x0100";
154285430Sbapt	match "release"		"0x0100";
155283961Sbapt	action "/usr/local/bin/coldsync -md -p /dev/$cdev -t usb";
156286982Sbapt};
157286982Sbapt
158286982Sbapt#
159285430Sbapt# Rescan scsi device-names on attach, but not detach.  However, it is
160285434Sbapt# disabled by default due to reports of problems.
161285434Sbapt#
162285434Sbaptattach 0 {
163283961Sbapt	device-name "$scsi-controller-regex";
164283961Sbapt//	action "camcontrol rescan all";
165286196Sbapt};
166285430Sbapt
167286196Sbapt# Don't even try to second guess what to do about drivers that don't
168286196Sbapt# match here.  Instead, pass it off to syslog.  Commented out for the
169283961Sbapt# moment, as the pnpinfo variable isn't set in devd yet.  Individual
170283961Sbapt# variables within the bus supplied pnpinfo are set.
171285133Sbaptnomatch 0 {
172286196Sbapt#	action "logger Unknown device: $pnpinfo $location $bus";
173285133Sbapt};
174285133Sbapt
175285133Sbapt# Various logging of unknown devices.
176285133Sbaptnomatch 10 {
177285133Sbapt	match "bus" "uhub[0-9]+";
178285133Sbapt	action "logger Unknown USB device: vendor $vendor product $product \
179285133Sbapt		bus $bus";
180286196Sbapt};
181285133Sbapt
182285133Sbapt# Some PC-CARDs don't offer numerical manufacturer/product IDs, just
183285133Sbapt# show the CIS info there.
184285133Sbaptnomatch 20 {
185285133Sbapt	match "bus" "pccard[0-9]+";
186285133Sbapt	match "manufacturer" "0xffffffff";
187285133Sbapt	match "product" "0xffffffff";
188286196Sbapt	action "logger Unknown PCCARD device: CISproduct $cisproduct \
189286196Sbapt		CIS-vendor $cisvendor bus $bus";
190285133Sbapt};
191285133Sbapt
192285137Sbaptnomatch 10 {
193285133Sbapt	match "bus" "pccard[0-9]+";
194286196Sbapt	action "logger Unknown PCCARD device: manufacturer $manufacturer \
195285133Sbapt		product $product CISproduct $cisproduct CIS-vendor \
196285133Sbapt		$cisvendor bus $bus";
197286196Sbapt};
198285133Sbapt
199285133Sbaptnomatch 10 {
200285133Sbapt	match "bus" "cardbus[0-9]+";
201285133Sbapt	action "logger Unknown Cardbus device: device $device class $class \
202286196Sbapt		vendor $vendor bus $bus";
203285133Sbapt};
204286196Sbapt
205285133Sbapt# Switch power profiles when the AC line state changes.
206285133Sbaptnotify 10 {
207285133Sbapt	match "system"		"ACPI";
208285133Sbapt	match "subsystem"	"ACAD";
209285133Sbapt	action "/etc/rc.d/power_profile $notify";
210285133Sbapt};
211286196Sbapt
212285133Sbapt# Notify all users before beginning emergency shutdown when we get
213285133Sbapt# a _CRT or _HOT thermal event and we're going to power down the system
214285133Sbapt# very soon.
215285133Sbaptnotify 10 {
216285133Sbapt	match "system"		"ACPI";
217286196Sbapt	match "subsystem"	"Thermal";
218286196Sbapt	match "notify"		"0xcc";
219285133Sbapt	action "logger -p kern.emerg 'WARNING: system temperature too high, shutting down soon!'";
220285137Sbapt};
221286196Sbapt
222285133Sbapt# Sample ZFS problem reports handling.
223285133Sbaptnotify 10 {
224285133Sbapt	match "system"		"ZFS";
225285133Sbapt	match "type"		"zpool";
226285133Sbapt	action "logger -p kern.err 'ZFS: failed to load zpool $pool'";
227285133Sbapt};
228285133Sbapt
229285133Sbaptnotify 10 {
230285133Sbapt	match "system"		"ZFS";
231285133Sbapt	match "type"		"vdev";
232285133Sbapt	action "logger -p kern.err 'ZFS: vdev failure, zpool=$pool type=$type'";
233285405Sbapt};
234286196Sbapt
235285405Sbaptnotify 10 {
236285405Sbapt	match "system"		"ZFS";
237286196Sbapt	match "type"		"data";
238285405Sbapt	action "logger -p kern.warn 'ZFS: zpool I/O failure, zpool=$pool error=$zio_err'";
239286196Sbapt};
240286196Sbapt
241286196Sbaptnotify 10 {
242286196Sbapt	match "system"		"ZFS";
243285405Sbapt	match "type"		"io";
244285405Sbapt	action "logger -p kern.warn 'ZFS: vdev I/O failure, zpool=$pool path=$vdev_path offset=$zio_offset size=$zio_size error=$zio_err'";
245285405Sbapt};
246285405Sbapt
247285405Sbaptnotify 10 {
248285405Sbapt	match "system"		"ZFS";
249286196Sbapt	match "type"		"checksum";
250286196Sbapt	action "logger -p kern.warn 'ZFS: checksum mismatch, zpool=$pool path=$vdev_path offset=$zio_offset size=$zio_size'";
251285405Sbapt};
252285405Sbapt
253285984Sbapt# User requested suspend, so perform preparation steps and then execute
254285405Sbapt# the actual suspend process.
255285405Sbaptnotify 10 {
256285405Sbapt	match "system"		"ACPI";
257285405Sbapt	match "subsystem"	"Suspend";
258285405Sbapt	action "/etc/rc.suspend acpi $notify";
259285405Sbapt};
260285405Sbaptnotify 10 {
261285405Sbapt	match "system"		"ACPI";
262285405Sbapt	match "subsystem"	"Resume";
263285405Sbapt	action "/etc/rc.resume acpi $notify";
264285405Sbapt};
265285405Sbapt
266285405Sbapt/* EXAMPLES TO END OF FILE
267285405Sbapt
268285405Sbapt# The following might be an example of something that a vendor might
269286196Sbapt# install if you were to add their device.  This might reside in
270285405Sbapt# /usr/local/etc/devd/deqna.conf.  A deqna is, in this hypothetical
271285405Sbapt# example, a pccard ethernet-like device.  Students of history may
272285405Sbapt# know other devices by this name, and will get the in-jokes in this
273286196Sbapt# entry.
274285405Sbaptnomatch 10 {
275286196Sbapt	match "bus" "pccard[0-9]+";
276285405Sbapt	match "manufacturer" "0x1234";
277286196Sbapt	match "product" "0x2323";
278286196Sbapt	action "kldload if_deqna";
279286196Sbapt};
280286196Sbaptattach 10 {
281285405Sbapt	device-name "deqna[0-9]+";
282285405Sbapt	action "/etc/pccard_ether $device-name start";
283286259Sed};
284286196Sbaptdetach 10 {
285286196Sbapt	device-name "deqna[0-9]+";
286286196Sbapt	action "/etc/pccard_ether $device-name stop";
287286196Sbapt};
288285405Sbapt
289285405Sbapt# Examples of notify hooks.  A notify is a generic way for a kernel
290285405Sbapt# subsystem to send event notification to userland.
291286196Sbapt#
292285405Sbapt# Here are some examples of ACPI notify handlers.  ACPI subsystems that
293285405Sbapt# generate notifies include the AC adapter, power/sleep buttons,
294285405Sbapt# control method batteries, lid switch, and thermal zones.
295285405Sbapt#
296285405Sbapt# Information returned is not always the same as the ACPI notify
297285405Sbapt# events.  See the ACPI specification for more information about
298285405Sbapt# notifies.  Here is the information returned for each subsystem:
299285405Sbapt#
300285405Sbapt# ACAD:		AC line state (0 is offline, 1 is online)
301285405Sbapt# Button:	Button pressed (0 for power, 1 for sleep)
302285405Sbapt# CMBAT:	ACPI battery events
303285405Sbapt# Lid:		Lid state (0 is closed, 1 is open)
304285405Sbapt# RCTL:		Resource limits
305285405Sbapt# Suspend, Resume: Suspend and resume notification
306285405Sbapt# Thermal:	ACPI thermal zone events
307285405Sbapt#
308285405Sbapt# This example calls a script when the AC state changes, passing the
309285405Sbapt# notify value as the first argument.  If the state is 0x00, it might
310285405Sbapt# call some sysctls to implement economy mode.  If 0x01, it might set
311285405Sbapt# the mode to performance.
312285405Sbaptnotify 10 {
313285405Sbapt	match "system"		"ACPI";
314286196Sbapt	match "subsystem"	"ACAD";
315285405Sbapt	action			"/etc/acpi_ac $notify";
316285405Sbapt};
317285405Sbapt
318285405Sbapt# This example works around a memory leak in PostgreSQL, restarting
319285405Sbapt# it when "user:pgsql:swap:devctl=1G" rctl(8) rule gets triggered.
320286196Sbaptnotify 0 {
321286196Sbapt	match "system"		"RCTL";
32220253Sjoerg	match "rule"		"user:70:swap:.*";
323286196Sbapt	action			"/usr/local/etc/rc.d/postgresql restart"
324286196Sbapt};
325286196Sbapt
32620253Sjoerg*/
32720267Sjoerg