144e1285cSBrad Davis# 244e1285cSBrad Davis# Refer to devd.conf(5) and devd(8) man pages for the details on how to 344e1285cSBrad Davis# run and configure devd. 444e1285cSBrad Davis# 544e1285cSBrad Davis 644e1285cSBrad Davis# NB: All regular expressions have an implicit ^$ around them. 744e1285cSBrad Davis# NB: device-name is shorthand for 'match device-name' 844e1285cSBrad Davis 944e1285cSBrad Davisoptions { 1044e1285cSBrad Davis # Each "directory" directive adds a directory to the list of 1144e1285cSBrad Davis # directories that we scan for files. Files are loaded in the order 1244e1285cSBrad Davis # that they are returned from readdir(3). The rule-sets are combined 1344e1285cSBrad Davis # to create a DFA that's used to match events to actions. 1444e1285cSBrad Davis directory "/etc/devd"; 1544e1285cSBrad Davis directory "/usr/local/etc/devd"; 1644e1285cSBrad Davis pid-file "/var/run/devd.pid"; 1744e1285cSBrad Davis 1844e1285cSBrad Davis # Setup some shorthand for regex that we use later in the file. 19e0ab0ff1SWarner Losh #XXX Yes, this is gross -- imp 2044e1285cSBrad Davis set wifi-driver-regex 21*e17944a8SBjoern A. Zeeb "(ath|ath[0-9]+k|bwi|bwn|ipw|iwlwifi|iwi|iwm|iwn|malo|mwl|mt79|otus|\ 2288e71cc0SBjoern A. Zeeb ral|rsu|rtw|rtwn|rum|run|uath|upgt|ural|urtw|wpi|wtap|zyd)[0-9]+"; 2344e1285cSBrad Davis}; 2444e1285cSBrad Davis 2544e1285cSBrad Davis# Note that the attach/detach with the highest value wins, so that one can 2644e1285cSBrad Davis# override these general rules. 2744e1285cSBrad Davis 2844e1285cSBrad Davis# 2944e1285cSBrad Davis# Configure the interface on attach. Due to a historical accident, this 307e4161c1SWarner Losh# script is called pccard_ether. We omit the usbus devices because those 316a8ed85fSCeri Davies# devices are associated with the USB Bus and provide an ifnet device to 321a658069SWarner Losh# allow usb traffic to be captured with usbdump(8). 3344e1285cSBrad Davis# 3444e1285cSBrad Davis# NB: DETACH events are ignored; the kernel should handle all cleanup 3544e1285cSBrad Davis# (routes, arp cache). Beware of races against immediate create 3644e1285cSBrad Davis# of a device with the same name; e.g. 3744e1285cSBrad Davis# ifconfig bridge0 destroy; ifconfig bridge0 create 3844e1285cSBrad Davis# 3944e1285cSBrad Davisnotify 0 { 4044e1285cSBrad Davis match "system" "IFNET"; 41bbf61f79SAndriy Voskoboinyk match "subsystem" "!(usbus|wlan)[0-9]+"; 4244e1285cSBrad Davis match "type" "ATTACH"; 4344e1285cSBrad Davis action "/etc/pccard_ether $subsystem start"; 4444e1285cSBrad Davis}; 4544e1285cSBrad Davis 4644e1285cSBrad Davis# 4744e1285cSBrad Davis# Like Ethernet devices, but separate because 802.11 require spawning 4844e1285cSBrad Davis# wlan(4) interface. 4944e1285cSBrad Davis# 5044e1285cSBrad Davisattach 0 { 5144e1285cSBrad Davis device-name "$wifi-driver-regex"; 5244e1285cSBrad Davis action "/etc/pccard_ether $device-name startchildren"; 5344e1285cSBrad Davis}; 5444e1285cSBrad Davisdetach 0 { 5544e1285cSBrad Davis device-name "$wifi-driver-regex"; 5644e1285cSBrad Davis action "/etc/pccard_ether $device-name stopchildren"; 5744e1285cSBrad Davis}; 5844e1285cSBrad Davis 5944e1285cSBrad Davis# An entry like this might be in a different file, but is included here 6044e1285cSBrad Davis# as an example of how to override things. Normally 'ed50' would match 6144e1285cSBrad Davis# the above attach/detach stuff, but the value of 100 makes it 6244e1285cSBrad Davis# hard wired to 1.2.3.4. 6344e1285cSBrad Davisattach 100 { 6444e1285cSBrad Davis device-name "ed50"; 6544e1285cSBrad Davis action "ifconfig $device-name inet 1.2.3.4 netmask 0xffff0000"; 6644e1285cSBrad Davis}; 6744e1285cSBrad Davisdetach 100 { 6844e1285cSBrad Davis device-name "ed50"; 6944e1285cSBrad Davis}; 7044e1285cSBrad Davis 7144e1285cSBrad Davis# Firmware downloader for Atheros AR3011 based USB Bluetooth devices 7244e1285cSBrad Davis#attach 100 { 7344e1285cSBrad Davis# match "vendor" "0x0cf3"; 7444e1285cSBrad Davis# match "product" "0x3000"; 7544e1285cSBrad Davis# action "sleep 2 && /usr/sbin/ath3kfw -d $device-name -f /usr/local/etc/ath3k-1.fw"; 7644e1285cSBrad Davis#}; 7744e1285cSBrad Davis 7844e1285cSBrad Davis# Notify all users before beginning emergency shutdown when we get 7944e1285cSBrad Davis# a _CRT or _HOT thermal event and we're going to power down the system 8044e1285cSBrad Davis# very soon. 8144e1285cSBrad Davisnotify 10 { 8244e1285cSBrad Davis match "system" "ACPI"; 8344e1285cSBrad Davis match "subsystem" "Thermal"; 8444e1285cSBrad Davis match "notify" "0xcc"; 856f6f0f28SWarner Losh action "logger -p kern.emerg WARNING: system temperature too high, shutting down soon!"; 8644e1285cSBrad Davis}; 8744e1285cSBrad Davis 8844e1285cSBrad Davis# User requested suspend, so perform preparation steps and then execute 8944e1285cSBrad Davis# the actual suspend process. 9044e1285cSBrad Davisnotify 10 { 9144e1285cSBrad Davis match "system" "ACPI"; 9244e1285cSBrad Davis match "subsystem" "Suspend"; 9344e1285cSBrad Davis action "/etc/rc.suspend acpi $notify"; 9444e1285cSBrad Davis}; 9544e1285cSBrad Davisnotify 10 { 9644e1285cSBrad Davis match "system" "ACPI"; 9744e1285cSBrad Davis match "subsystem" "Resume"; 9844e1285cSBrad Davis action "/etc/rc.resume acpi $notify"; 9944e1285cSBrad Davis}; 10044e1285cSBrad Davis 10144e1285cSBrad Davis/* EXAMPLES TO END OF FILE 10244e1285cSBrad Davis 10344e1285cSBrad Davis# Examples of notify hooks. A notify is a generic way for a kernel 10444e1285cSBrad Davis# subsystem to send event notification to userland. 10544e1285cSBrad Davis 10644e1285cSBrad Davis# Here are some examples of ACPI notify handlers. ACPI subsystems that 10744e1285cSBrad Davis# generate notifies include the AC adapter, power/sleep buttons, 10844e1285cSBrad Davis# control method batteries, lid switch, and thermal zones. 10944e1285cSBrad Davis# 11044e1285cSBrad Davis# Information returned is not always the same as the ACPI notify 11144e1285cSBrad Davis# events. See the ACPI specification for more information about 11244e1285cSBrad Davis# notifies. Here is the information returned for each subsystem: 11344e1285cSBrad Davis# 11444e1285cSBrad Davis# ACAD: AC line state (0 is offline, 1 is online) 11544e1285cSBrad Davis# Button: Button pressed (0 for power, 1 for sleep) 11644e1285cSBrad Davis# CMBAT: ACPI battery events 11744e1285cSBrad Davis# Lid: Lid state (0 is closed, 1 is open) 11844e1285cSBrad Davis# Suspend, Resume: Suspend and resume notification 11944e1285cSBrad Davis# Thermal: ACPI thermal zone events 12044e1285cSBrad Davis# 12144e1285cSBrad Davis# This example calls a script when the AC state changes, passing the 12244e1285cSBrad Davis# notify value as the first argument. If the state is 0x00, it might 12344e1285cSBrad Davis# call some sysctls to implement economy mode. If 0x01, it might set 12444e1285cSBrad Davis# the mode to performance. 12544e1285cSBrad Davisnotify 10 { 12644e1285cSBrad Davis match "system" "ACPI"; 12744e1285cSBrad Davis match "subsystem" "ACAD"; 12844e1285cSBrad Davis action "/etc/acpi_ac $notify"; 12944e1285cSBrad Davis}; 13044e1285cSBrad Davis 13144e1285cSBrad Davis# This example works around a memory leak in PostgreSQL, restarting 13244e1285cSBrad Davis# it when the "user:postgres:swap:devctl=1G" rctl(8) rule gets triggered. 13344e1285cSBrad Davisnotify 0 { 13444e1285cSBrad Davis match "system" "RCTL"; 13544e1285cSBrad Davis match "rule" "user:770:swap:.*"; 13644e1285cSBrad Davis action "service postgresql restart"; 13744e1285cSBrad Davis}; 13844e1285cSBrad Davis 13944e1285cSBrad Davis# Handle userland coredumps. 14044e1285cSBrad Davis# This commented out handler makes it possible to run an 14144e1285cSBrad Davis# automated debugging session after the core dump is generated. 14244e1285cSBrad Davis# Replace action with a proper coredump handler, but be aware that 14344e1285cSBrad Davis# it will run with elevated privileges. 14444e1285cSBrad Davisnotify 10 { 14544e1285cSBrad Davis match "system" "kernel"; 14644e1285cSBrad Davis match "subsystem" "signal"; 14744e1285cSBrad Davis match "type" "coredump"; 14844e1285cSBrad Davis action "logger $comm $core"; 14944e1285cSBrad Davis}; 15044e1285cSBrad Davis 15144e1285cSBrad Davis# Let the init(8) know there's a new USB serial interface it might 15244e1285cSBrad Davis# want to run getty(8) for. This includes device-side tty created 15344e1285cSBrad Davis# by usb_template(4). 15444e1285cSBrad Davisnotify 100 { 15544e1285cSBrad Davis match "system" "DEVFS"; 15644e1285cSBrad Davis match "subsystem" "CDEV"; 15744e1285cSBrad Davis match "type" "CREATE"; 15844e1285cSBrad Davis match "cdev" "ttyU[0-9]+"; 15944e1285cSBrad Davis action "/sbin/init q"; 16044e1285cSBrad Davis}; 16144e1285cSBrad Davis 16244e1285cSBrad Davis*/ 163