1108983Simp# $FreeBSD: stable/11/etc/devd.conf 363729 2020-07-31 11:14:11Z 0mp $ 2108983Simp# 3108983Simp# Refer to devd.conf(5) and devd(8) man pages for the details on how to 4108983Simp# run and configure devd. 5108983Simp# 6108983Simp 7108983Simp# NB: All regular expressions have an implicit ^$ around them. 8108983Simp# NB: device-name is shorthand for 'match device-name' 9108983Simp 10108983Simpoptions { 11225861Swblock # Each "directory" directive adds a directory to the list of 12225861Swblock # directories that we scan for files. Files are loaded in the order 13225861Swblock # that they are returned from readdir(3). The rule-sets are combined 14225861Swblock # to create a DFA that's used to match events to actions. 15108983Simp directory "/etc/devd"; 16108983Simp directory "/usr/local/etc/devd"; 17108983Simp pid-file "/var/run/devd.pid"; 18108983Simp 19108983Simp # Setup some shorthand for regex that we use later in the file. 20148471Simp #XXX Yes, these are gross -- imp 21108983Simp set scsi-controller-regex 22139027Sbrueffer "(aac|adv|adw|aha|ahb|ahc|ahd|aic|amd|amr|asr|bt|ciss|ct|dpt|\ 23326676Sasomers esp|ida|iir|ips|isp|mlx|mly|mpr|mps|mpt|ncr|ncv|nsp|stg|sym|\ 24326676Sasomers trm|wds)[0-9]+"; 25287394Sglebius set wifi-driver-regex 26343467Savos "(ath|bwi|bwn|ipw|iwi|iwm|iwn|malo|mwl|otus|ral|rsu|rum|run|\ 27343467Savos uath|upgt|ural|urtw|urtwn|wi|wpi|wtap|zyd)[0-9]+"; 28108983Simp}; 29108983Simp 30108983Simp# Note that the attach/detach with the highest value wins, so that one can 31108983Simp# override these general rules. 32108983Simp 33108983Simp# 34159126Sthompsa# Configure the interface on attach. Due to a historical accident, this 35159126Sthompsa# script is called pccard_ether. 36108983Simp# 37187743Ssam# NB: DETACH events are ignored; the kernel should handle all cleanup 38225861Swblock# (routes, arp cache). Beware of races against immediate create 39225861Swblock# of a device with the same name; e.g. 40247660Sschweikh# ifconfig bridge0 destroy; ifconfig bridge0 create 41187743Ssam# 42159126Sthompsanotify 0 { 43159126Sthompsa match "system" "IFNET"; 44343641Savos match "subsystem" "!(usbus|wlan)[0-9]+"; 45159126Sthompsa match "type" "ATTACH"; 46159126Sthompsa action "/etc/pccard_ether $subsystem start"; 47108983Simp}; 48108983Simp 49147088Sbrooks# 50225861Swblock# Try to start dhclient on Ethernet-like interfaces when the link comes 51147088Sbrooks# up. Only devices that are configured to support DHCP will actually 52216983Sjpaetzel# run it. No link down rule exists because dhclient automatically exits 53147088Sbrooks# when the link goes down. 54147088Sbrooks# 55147088Sbrooksnotify 0 { 56147088Sbrooks match "system" "IFNET"; 57147088Sbrooks match "type" "LINK_UP"; 58148642Ssam media-type "ethernet"; 59175683Smtm action "/etc/rc.d/dhclient quietstart $subsystem"; 60147088Sbrooks}; 61147088Sbrooks 62148642Ssam# 63287394Sglebius# Like Ethernet devices, but separate because 802.11 require spawning 64287394Sglebius# wlan(4) interface. 65148642Ssam# 66287394Sglebiusattach 0 { 67287394Sglebius device-name "$wifi-driver-regex"; 68287394Sglebius action "/etc/pccard_ether $device-name startchildren"; 69287394Sglebius}; 70148642Ssamdetach 0 { 71287394Sglebius device-name "$wifi-driver-regex"; 72287394Sglebius action "/etc/pccard_ether $device-name stopchildren"; 73148642Ssam}; 74148642Ssamnotify 0 { 75148642Ssam match "system" "IFNET"; 76148642Ssam match "type" "LINK_UP"; 77148642Ssam media-type "802.11"; 78175683Smtm action "/etc/rc.d/dhclient quietstart $subsystem"; 79148642Ssam}; 80148642Ssam 81108983Simp# An entry like this might be in a different file, but is included here 82108983Simp# as an example of how to override things. Normally 'ed50' would match 83108983Simp# the above attach/detach stuff, but the value of 100 makes it 84139281Sbrueffer# hard wired to 1.2.3.4. 85108983Simpattach 100 { 86108983Simp device-name "ed50"; 87108983Simp action "ifconfig $device-name inet 1.2.3.4 netmask 0xffff0000"; 88108983Simp}; 89108983Simpdetach 100 { 90108983Simp device-name "ed50"; 91108983Simp}; 92108983Simp 93225861Swblock# When a USB Bluetooth dongle appears, activate it 94152326Semaxattach 100 { 95152326Semax device-name "ubt[0-9]+"; 96175683Smtm action "/etc/rc.d/bluetooth quietstart $device-name"; 97152326Semax}; 98152326Semaxdetach 100 { 99152326Semax device-name "ubt[0-9]+"; 100175683Smtm action "/etc/rc.d/bluetooth quietstop $device-name"; 101152326Semax}; 102152326Semax 103215195Semax# Firmware downloader for Atheros AR3011 based USB Bluetooth devices 104215195Semax#attach 100 { 105215195Semax# match "vendor" "0x0cf3"; 106215195Semax# match "product" "0x3000"; 107215195Semax# action "sleep 2 && /usr/sbin/ath3kfw -d $device-name -f /usr/local/etc/ath3k-1.fw"; 108215195Semax#}; 109215195Semax 110139281Sbrueffer# When a USB keyboard arrives, attach it as the console keyboard. 111134584Sbrooksattach 100 { 112134584Sbrooks device-name "ukbd0"; 113156782Semax action "/etc/rc.d/syscons setkeyboard /dev/ukbd0"; 114134584Sbrooks}; 115134584Sbrooksdetach 100 { 116134584Sbrooks device-name "ukbd0"; 117156331Semax action "/etc/rc.d/syscons setkeyboard /dev/kbd0"; 118134584Sbrooks}; 119134584Sbrooks 120240891Shselaskynotify 100 { 121240891Shselasky match "system" "DEVFS"; 122240891Shselasky match "subsystem" "CDEV"; 123240891Shselasky match "type" "CREATE"; 124261260Shselasky match "cdev" "atp[0-9]+"; 125261260Shselasky 126261260Shselasky action "/etc/rc.d/moused quietstart $cdev"; 127261260Shselasky}; 128261260Shselasky 129261260Shselaskynotify 100 { 130261260Shselasky match "system" "DEVFS"; 131261260Shselasky match "subsystem" "CDEV"; 132261260Shselasky match "type" "CREATE"; 133240891Shselasky match "cdev" "ums[0-9]+"; 134240891Shselasky 135240891Shselasky action "/etc/rc.d/moused quietstart $cdev"; 136138175Siedowse}; 137138175Siedowse 138240891Shselaskynotify 100 { 139240891Shselasky match "system" "DEVFS"; 140240891Shselasky match "subsystem" "CDEV"; 141261260Shselasky match "type" "CREATE"; 142261260Shselasky match "cdev" "wsp[0-9]+"; 143261260Shselasky 144261260Shselasky action "/etc/rc.d/moused quietstart $cdev"; 145261260Shselasky}; 146261260Shselasky 147261260Shselaskynotify 100 { 148261260Shselasky match "system" "DEVFS"; 149261260Shselasky match "subsystem" "CDEV"; 150240891Shselasky match "type" "DESTROY"; 151240891Shselasky match "cdev" "ums[0-9]+"; 152240891Shselasky 153240891Shselasky action "/etc/rc.d/moused stop $cdev"; 154208060Sdougb}; 155179804Skmacy 156153300Siedowse# This entry starts the ColdSync tool in daemon mode. Make sure you have an up 157153300Siedowse# to date /usr/local/etc/palms. We override the 'listen' settings for port and 158153300Siedowse# type in /usr/local/etc/coldsync.conf. 159207020Sthompsanotify 100 { 160207020Sthompsa match "system" "USB"; 161207020Sthompsa match "subsystem" "DEVICE"; 162207020Sthompsa match "type" "ATTACH"; 163207020Sthompsa match "vendor" "0x082d"; 164207020Sthompsa match "product" "0x0100"; 165207020Sthompsa match "release" "0x0100"; 166207020Sthompsa action "/usr/local/bin/coldsync -md -p /dev/$cdev -t usb"; 167153300Siedowse}; 168153300Siedowse 169108983Simp# 170247660Sschweikh# Rescan SCSI device-names on attach, but not detach. However, it is 171148471Simp# disabled by default due to reports of problems. 172108983Simp# 173108983Simpattach 0 { 174108983Simp device-name "$scsi-controller-regex"; 175131646Simp// action "camcontrol rescan all"; 176108983Simp}; 177108983Simp 178108983Simp# Don't even try to second guess what to do about drivers that don't 179114799Simp# match here. Instead, pass it off to syslog. Commented out for the 180166754Simp# moment, as the pnpinfo variable isn't set in devd yet. Individual 181166754Simp# variables within the bus supplied pnpinfo are set. 182119254Simpnomatch 0 { 183114852Simp# action "logger Unknown device: $pnpinfo $location $bus"; 184119254Simp}; 185108983Simp 186166701Sjoerg# Various logging of unknown devices. 187166701Sjoergnomatch 10 { 188166701Sjoerg match "bus" "uhub[0-9]+"; 189166701Sjoerg action "logger Unknown USB device: vendor $vendor product $product \ 190166701Sjoerg bus $bus"; 191166701Sjoerg}; 192166701Sjoerg 193166701Sjoerg# Some PC-CARDs don't offer numerical manufacturer/product IDs, just 194166701Sjoerg# show the CIS info there. 195166701Sjoergnomatch 20 { 196166701Sjoerg match "bus" "pccard[0-9]+"; 197166701Sjoerg match "manufacturer" "0xffffffff"; 198166701Sjoerg match "product" "0xffffffff"; 199166701Sjoerg action "logger Unknown PCCARD device: CISproduct $cisproduct \ 200166701Sjoerg CIS-vendor $cisvendor bus $bus"; 201166701Sjoerg}; 202166701Sjoerg 203166701Sjoergnomatch 10 { 204166701Sjoerg match "bus" "pccard[0-9]+"; 205166701Sjoerg action "logger Unknown PCCARD device: manufacturer $manufacturer \ 206166701Sjoerg product $product CISproduct $cisproduct CIS-vendor \ 207166701Sjoerg $cisvendor bus $bus"; 208166701Sjoerg}; 209166701Sjoerg 210166701Sjoergnomatch 10 { 211166701Sjoerg match "bus" "cardbus[0-9]+"; 212166701Sjoerg action "logger Unknown Cardbus device: device $device class $class \ 213166701Sjoerg vendor $vendor bus $bus"; 214166701Sjoerg}; 215166701Sjoerg 216139281Sbrueffer# Switch power profiles when the AC line state changes. 217123626Snjlnotify 10 { 218123626Snjl match "system" "ACPI"; 219123626Snjl match "subsystem" "ACAD"; 220125366Snjl action "/etc/rc.d/power_profile $notify"; 221123626Snjl}; 222123626Snjl 223125366Snjl# Notify all users before beginning emergency shutdown when we get 224125366Snjl# a _CRT or _HOT thermal event and we're going to power down the system 225125366Snjl# very soon. 226125366Snjlnotify 10 { 227125366Snjl match "system" "ACPI"; 228125366Snjl match "subsystem" "Thermal"; 229125366Snjl match "notify" "0xcc"; 230125366Snjl action "logger -p kern.emerg 'WARNING: system temperature too high, shutting down soon!'"; 231125366Snjl}; 232125366Snjl 233170976Snjl# User requested suspend, so perform preparation steps and then execute 234170976Snjl# the actual suspend process. 235170976Snjlnotify 10 { 236170976Snjl match "system" "ACPI"; 237170976Snjl match "subsystem" "Suspend"; 238170976Snjl action "/etc/rc.suspend acpi $notify"; 239170976Snjl}; 240170976Snjlnotify 10 { 241170976Snjl match "system" "ACPI"; 242170976Snjl match "subsystem" "Resume"; 243170976Snjl action "/etc/rc.resume acpi $notify"; 244170976Snjl}; 245170976Snjl 246108983Simp/* EXAMPLES TO END OF FILE 247108983Simp 248225861Swblock# An example of something that a vendor might install if you were to 249225861Swblock# add their device. This might reside in /usr/local/etc/devd/deqna.conf. 250225861Swblock# A deqna is, in this hypothetical example, a pccard ethernet-like device. 251225861Swblock# Students of history may know other devices by this name, and will get 252225861Swblock# the in-jokes in this entry. 253108983Simpnomatch 10 { 254108983Simp match "bus" "pccard[0-9]+"; 255108983Simp match "manufacturer" "0x1234"; 256108983Simp match "product" "0x2323"; 257330316Seadler action "kldload -n if_deqna"; 258108983Simp}; 259108983Simpattach 10 { 260108983Simp device-name "deqna[0-9]+"; 261108983Simp action "/etc/pccard_ether $device-name start"; 262108983Simp}; 263108983Simpdetach 10 { 264108983Simp device-name "deqna[0-9]+"; 265108983Simp action "/etc/pccard_ether $device-name stop"; 266108983Simp}; 267108983Simp 268121493Snjl# Examples of notify hooks. A notify is a generic way for a kernel 269121493Snjl# subsystem to send event notification to userland. 270225861Swblock 271121493Snjl# Here are some examples of ACPI notify handlers. ACPI subsystems that 272121493Snjl# generate notifies include the AC adapter, power/sleep buttons, 273121493Snjl# control method batteries, lid switch, and thermal zones. 274121493Snjl# 275121493Snjl# Information returned is not always the same as the ACPI notify 276121493Snjl# events. See the ACPI specification for more information about 277121493Snjl# notifies. Here is the information returned for each subsystem: 278121493Snjl# 279247660Sschweikh# ACAD: AC line state (0 is offline, 1 is online) 280247660Sschweikh# Button: Button pressed (0 for power, 1 for sleep) 281247660Sschweikh# CMBAT: ACPI battery events 282247660Sschweikh# Lid: Lid state (0 is closed, 1 is open) 283170976Snjl# Suspend, Resume: Suspend and resume notification 284247660Sschweikh# Thermal: ACPI thermal zone events 285121493Snjl# 286121493Snjl# This example calls a script when the AC state changes, passing the 287121493Snjl# notify value as the first argument. If the state is 0x00, it might 288121493Snjl# call some sysctls to implement economy mode. If 0x01, it might set 289121493Snjl# the mode to performance. 290121493Snjlnotify 10 { 291121493Snjl match "system" "ACPI"; 292121493Snjl match "subsystem" "ACAD"; 293121493Snjl action "/etc/acpi_ac $notify"; 294121493Snjl}; 295220168Strasz 296220168Strasz# This example works around a memory leak in PostgreSQL, restarting 297316372Sasomers# it when the "user:postgres:swap:devctl=1G" rctl(8) rule gets triggered. 298220168Strasznotify 0 { 299220168Strasz match "system" "RCTL"; 300316372Sasomers match "rule" "user:770:swap:.*"; 301238308Shrs action "/usr/local/etc/rc.d/postgresql restart"; 302220168Strasz}; 303220168Strasz 304277171Strasz# Discard autofs caches, useful for the -media special map. 305275681Strasznotify 100 { 306277171Strasz match "system" "GEOM"; 307277171Strasz match "subsystem" "DEV"; 308277171Strasz action "/usr/sbin/automount -c"; 309275681Strasz}; 310275681Strasz 311278479Srpaulo# Handle userland coredumps. 312278479Srpaulo# This commented out handler makes it possible to run an 313278479Srpaulo# automated debugging session after the core dump is generated. 314278479Srpaulo# Replace action with a proper coredump handler, but be aware that 315278479Srpaulo# it will run with elevated privileges. 316278479Srpaulonotify 10 { 317278479Srpaulo match "system" "kernel"; 318278479Srpaulo match "subsystem" "signal"; 319278479Srpaulo match "type" "coredump"; 320278479Srpaulo action "logger $comm $core"; 321278479Srpaulo}; 322278479Srpaulo 323108983Simp*/ 324