xref: /freebsd/sbin/devd/devd.conf.5 (revision f39bffc62c1395bde25d152c7f68fdf7cbaab414)
1.\"
2.\" Copyright (c) 2002 M. Warner Losh
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. The name of the author may not be used to endorse or promote products
11.\"    derived from this software without specific prior written permission.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.\" The section on comments was taken from named.conf.5, which has the
28.\" following copyright:
29.\" Copyright (c) 1999-2000 by Internet Software Consortium
30.\"
31.\" Permission to use, copy, modify, and distribute this software for any
32.\" purpose with or without fee is hereby granted, provided that the above
33.\" copyright notice and this permission notice appear in all copies.
34.\"
35.\" THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
36.\" ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
37.\" OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
38.\" CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
39.\" DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
40.\" PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
41.\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
42.\" SOFTWARE.
43.\"
44.Dd October 8, 2016
45.Dt DEVD.CONF 5
46.Os
47.Sh NAME
48.Nm devd.conf
49.Nd configuration file for
50.Xr devd 8
51.Sh DESCRIPTION
52.Ss General Syntax
53A
54.Xr devd 8
55configuration consists of two general features, statements
56and comments.
57All statements end with a semicolon.
58Many statements can contain substatements, which are also
59terminated with a semicolon.
60.Pp
61The following statements are supported:
62.Bl -tag -width ".Ic options"
63.It Ic attach
64Specifies various matching criteria and actions to perform when
65a newly attached device matches said criteria.
66.It Ic detach
67Specifies various matching criteria and actions to perform when
68a newly detached device matches said criteria.
69.It Ic nomatch
70Specifies various matching criteria and actions to perform when
71no device driver currently loaded in the kernel claims a (new)
72device.
73.It Ic notify
74Specifies various matching criteria and actions to perform when the kernel
75sends an event notification to userland.
76.It Ic options
77Specifies various options and parameters for the operation of
78.Xr devd 8 .
79.El
80.Pp
81Statements may occur in any order in the configuration file, and may be
82repeated as often as required.
83Further details on the syntax and meaning of each statement and their
84substatements are explained below.
85.Pp
86Each statement, except
87.Ic options
88has a priority (an arbitrary number) associated with it, where
89.Ql 0
90is defined as the lowest priority.
91If two statements match the same event, only the action of the statement with
92highest priority will be executed.
93In this way generic statements can be overridden for devices or
94notifications that require special attention.
95.Pp
96The general syntax of a statement is:
97.Bd -literal -offset indent
98statement priority {
99	substatement "value";
100	...
101	substatement "value";
102};
103.Ed
104.Ss Sub-statements
105The following sub-statements are supported within the
106.Ic options
107statement.
108.Bl -tag -width ".Ic directory"
109.It Ic directory Qq Ar /some/path ;
110Adds the given directory to the list of directories from which
111.Xr devd 8
112will read all files named "*.conf" as further
113configuration files.
114Any number of
115.Ic directory
116statements can be used.
117.It Ic pid-file Qq Pa /var/run/devd.pid ;
118Specifies PID file.
119.It Ic set Ar regexp-name Qq Ar (some|regexp) ;
120Creates a regular expression and assigns it to the variable
121.Ar regexp-name .
122The variable is available throughout the rest of
123the configuration file.
124If the string begins with
125.Ql \&! ,
126it matches if the regular expression formed by the rest of the string
127does not match.
128All regular expressions have an implicit
129.Ql ^$
130around them.
131.El
132.Pp
133The following sub-statements are supported within the
134.Ic attach
135and
136.Ic detach
137statements.
138.Bl -tag -width ".Ic directory"
139.It Ic action Qq Ar command ;
140Command to execute upon a successful match.
141Example
142.Dq Li "/etc/pccard_ether $device-name start" .
143.It Ic class Qq Ar string ;
144This is shorthand for
145.Dq Ic match Qo Li class Qc Qq Ar string .
146.It Ic device-name Qq string ;
147This is shorthand for
148.Dq Ic match Qo Li device-name Qc Qq Ar string .
149This matches a device named
150.Ar string ,
151which is allowed to be a regular expression or a variable previously created
152containing a regular expression.
153The
154.Dq Li device-name
155variable
156is available for later use with the
157.Ic action
158statement.
159.It Ic match Qo Ar variable Qc Qq Ar value ;
160Matches the content of
161.Ar value
162against
163.Ar variable ;
164the content of
165.Ar value
166may be a regular expression.
167Not required during
168.Ic attach
169nor
170.Ic detach
171events since the
172.Ic device-name
173statement takes care of all device matching.
174For a partial list of variables, see below.
175.It Ic media-type Qq Ar string ;
176For network devices,
177.Ic media-type
178will match devices that have the given media type.
179Valid media types are:
180.Dq Li Ethernet ,
181.Dq Li Tokenring ,
182.Dq Li FDDI ,
183.Dq Li 802.11 ,
184and
185.Dq Li ATM .
186.It Ic subdevice Qq Ar string ;
187This is shorthand for
188.Dq Ic match Qo Li subdevice Qc Qq Ar string .
189.El
190.Pp
191The following sub-statements are supported within the
192.Ic nomatch
193statement.
194.Bl -tag -width ".Ic directory"
195.It Ic action Qq Ar command ;
196Same as above.
197.It Ic match Qo Ar variable Qc Qq Ar value ;
198Matches the content of
199.Ar value
200against
201.Ar variable ;
202the content of
203.Ar value
204may be a regular expression.
205For a partial list of variables, see below.
206.El
207.Pp
208The following sub-statements are supported within the
209.Ic notify
210statement.
211The
212.Dq Li notify
213variable is available inside this statement and contains, a value, depending
214on which system and subsystem that delivered the event.
215.Bl -tag -width ".Ic directory"
216.It Ic action Qq Ar command ;
217Command to execute upon a successful match.
218Example
219.Dq Li "/etc/rc.d/power_profile $notify" .
220.It Ic match Qo Ar system | subsystem | type | notify Qc Qq Ar value ;
221Any number of
222.Ic match
223statements can exist within a
224.Ic notify
225statement;
226.Ar value
227can be either a fixed string or a regular expression.
228Below is a list of available systems, subsystems, and types.
229.It Ic media-type Qq Ar string ;
230See above.
231.El
232.Ss Variables that can be used with the match statement
233A partial list of variables and their possible values that can be used together
234with the
235.Ic match
236statement.
237The variables are published by the bus based on characteristics of the device
238that generated the event (for device events).
239Variables for other classes of events are dependent on those events.
240.Pp
241.Bl -tag -width ".Li manufacturer" -compact
242.It Ic Variable
243.Ic Description
244.It Li *
245The entire message from the current event
246.It Li _
247The entire message from the current event, after the initial type character
248.It Li timestamp
249The time this event was processed, in seconds since 1970 dot fraction
250.It Li bus
251Device name of parent bus.
252.It Li cdev
253Device node path if one is created by the
254.Xr devfs 5
255filesystem.
256.It Li cisproduct
257CIS-product.
258.It Li cisvendor
259CIS-vendor.
260.It Li class
261Device class.
262.It Li device
263Device ID.
264.It Li devclass
265Device Class (USB)
266.It Li devsubclass
267Device Sub-class (USB)
268.It Li device-name
269Name of attached/detached device.
270.It Li endpoints
271Endpoint count (USB)
272.It Li function
273Card functions.
274.It Li interface
275Interface ID (USB)
276.It Li intclass
277Interface Class (USB)
278.It Li intprotocol
279Interface Protocol  (USB)
280.It Li intsubclass
281Interface Sub-class (USB)
282.It Li jail
283Jail name for the process triggering the rule (RCTL)
284.It Li manufacturer
285Manufacturer ID (pccard).
286.It Li mode
287Peripheral mode (USB)
288.It Li notify
289Match the value of the
290.Dq Li notify
291variable.
292.It Li parent
293Parent device
294.It Li pid
295PID of the process triggering the rule (RCTL)
296.It Li port
297Hub port number (USB)
298.It Li product
299Product ID (pccard/USB).
300.It Li release
301Hardware revision (USB)
302.It Li ruid
303Real UID of the process triggering the rule (RCTL)
304.It Li rule
305Rule (RCTL)
306.It Li sernum
307Serial Number (USB).
308.It Li slot
309Card slot.
310.It Li subvendor
311Sub-vendor ID.
312.It Li subdevice
313Sub-device ID.
314.It Li subsystem
315Matches a subsystem of a system, see below.
316.It Li system
317Matches a system type, see below.
318.It Li type
319Type of notification, see below.
320.It Li vendor
321Vendor ID.
322.El
323.Ss Notify matching
324A partial list of systems, subsystems, and types used within the
325.Ic notify
326mechanism.
327.Pp
328.Bl -tag -width ".Li coretemp" -compact
329.It Sy System
330.It Li ACPI
331Events related to the ACPI subsystem.
332.Bl -tag -width ".Sy Subsystem" -compact
333.It Sy Subsystem
334.It Li ACAD
335AC line state ($notify=0x00 is offline, 0x01 is online).
336.It Li Button
337Button state ($notify=0x00 is power, 0x01 is sleep).
338.It Li CMBAT
339Battery events.
340.It Li Lid
341Lid state ($notify=0x00 is closed, 0x01 is open).
342.It Li PROCESSOR
343Processor state/configuration ($notify=0x81 is a change in available Cx states).
344.It Li Resume
345Resume notification.
346.It Li Suspend
347Suspend notification.
348.It Li Thermal
349Thermal zone events.
350.El
351.Pp
352.It Li CARP
353Events related to the
354.Xr carp 4
355protocol.
356.Bl -tag -width ".Sy Subsystem" -compact
357.It Sy Subsystem
358.It Ar vhid@interface
359The
360.Dq subsystem
361contains the actual CARP vhid and the name of the network interface
362on which the event took place.
363.Bl -tag -width ".Li MASTER" -compact
364.It Sy Type
365.It Li MASTER
366Node become the master for a virtual host.
367.It Li BACKUP
368Node become the backup for a virtual host.
369.El
370.El
371.Pp
372.It Li IFNET
373Events related to the network subsystem.
374.Bl -tag -width ".Sy Subsystem" -compact
375.It Sy Subsystem
376.It Ar interface
377The
378.Dq subsystem
379is the actual name of the network interface on which the event
380took place.
381.Bl -tag -width ".Li LINK_DOWN" -compact
382.It Sy Type
383.It Li LINK_UP
384Carrier status changed to UP.
385.It Li LINK_DOWN
386Carrier status changed to DOWN.
387.It Li ATTACH
388The network interface is attached to the system.
389.It Li DETACH
390The network interface is detached from the system.
391.El
392.El
393.Pp
394.It Li DEVFS
395Events related to the
396.Xr devfs 5
397filesystem.
398.Bl -tag -width ".Sy Subsystem" -compact
399.It Sy Subsystem
400.It Li CDEV
401.Bl -tag -width ".Li DESTROY" -compact
402.It Sy Type
403.It Li CREATE
404The
405.Xr devfs 5
406node is created.
407.It Li DESTROY
408The
409.Xr devfs 5
410node is destroyed.
411.El
412.El
413.Pp
414.It Li GEOM
415Events related to the
416.Xr geom 4
417framework.
418The difference compared to
419.Li DEVFS
420is that
421.Li GEOM
422only includes disk-like devices.
423.Bl -tag -width ".Sy Subsystem" -compact
424.It Sy Subsystem
425.It Li DEV
426.Bl -tag -width ".Li MEDIACHANGE" -compact
427.It Sy Type
428.It Li CREATE
429A
430.Xr geom 4
431device node is created.
432.It Li DESTROY
433A
434.Xr geom 4
435device node is destroyed.
436.It Li GEOM::physpath
437The physical path of a device has changed.
438.It Li MEDIACHANGE
439Physical media has changed.
440.El
441.El
442.Pp
443.It Li RCTL
444Events related to the
445.Xr rctl 8
446framework.
447.Bl -tag -width ".Sy Subsystem" -compact
448.It Sy Subsystem
449.It Li rule
450.Bl -tag -width ".Li matched" -compact
451.It Sy Type
452.It Li matched
453A rule with action specified as "devctl" was triggered.
454.El
455.El
456.Pp
457.It Li USB
458Events related to the USB subsystem.
459.Bl -tag -width ".Sy Subsystem" -compact
460.It Sy Subsystem
461.It Li DEVICE
462.Bl -tag -width ".Li DETACH" -compact
463.It Sy Type
464.It Li ATTACH
465USB device is attached to the system.
466.It Li DETACH
467USB device is detached from the system.
468.El
469.It Li INTERFACE
470.Bl -tag -width ".Li DETACH" -compact
471.It Sy Type
472.It Li ATTACH
473USB interface is attached to a device.
474.It Li DETACH
475USB interface is detached from a device.
476.El
477.El
478.Pp
479.It Li coretemp
480Events related to the
481.Xr coretemp 4
482device.
483.Bl -tag -width ".Sy Subsystem" -compact
484.It Sy Subsystem
485.It Li Thermal
486Notification that the CPU core has reached critical temperature.
487.Bl -tag -width ".Ar temperature" -compact
488.It Sy Type
489.It Ar temperature
490String containing the temperature of the core that has become too hot.
491.El
492.El
493.Pp
494.It Li kern
495Events related to the kernel.
496.Bl -tag -width ".Sy Subsystem" -compact
497.It Sy Subsystem
498.It Li power
499Information about the state of the system.
500.Bl -tag -width ".li resume" -compact
501.It Sy Type
502.It Li resume
503Notification that the system has woken from the suspended state.
504.El
505.El
506.Pp
507.It Li CAM
508Events related to the
509.Xr cam 4
510system.
511.Bl -tag -width ".Sy Subsystem" -compact
512.It Sy Subsystem
513.It Li periph
514Events related to peripheral devices.
515.Bl -tag -width ".li timeout" -compact
516.It Sy Type
517.It Li error
518Generic errors.
519.It Li timeout
520Command timeouts.
521.El
522.El
523.El
524.Pp
525A link state change to UP on the interface
526.Dq Li fxp0
527would result in the following notify event:
528.Bd -literal -offset indent
529system=IFNET, subsystem=fxp0, type=LINK_UP
530.Ed
531.Pp
532An AC line state change to
533.Dq offline
534would result in the following event:
535.Bd -literal -offset indent
536system=ACPI, subsystem=ACAD, notify=0x00
537.Ed
538.Ss Comments
539Comments may appear anywhere that whitespace may appear in a
540configuration file.
541To appeal to programmers of all kinds, they can
542be written in C, C++, or shell/Perl constructs.
543.Pp
544C-style comments start with the two characters
545.Ql /*
546(slash, star) and end with
547.Ql */
548(star, slash).
549Because they are completely delimited with these characters,
550they can be used to comment only a portion of a line or to span
551multiple lines.
552.Pp
553C-style comments cannot be nested.
554For example, the following is
555not valid because the entire comment ends with the first
556.Ql */ :
557.Bd -literal -offset indent
558/* This is the start of a comment.
559   This is still part of the comment.
560/* This is an incorrect attempt at nesting a comment. */
561   This is no longer in any comment. */
562.Ed
563.Pp
564C++-style comments start with the two characters
565.Ql //
566(slash, slash) and continue to the end of the physical line.
567They cannot be continued across multiple physical lines; to have
568one logical comment span multiple lines, each line must use the
569.Ql //
570pair.
571For example:
572.Bd -literal -offset indent
573// This is the start of a comment.  The next line
574// is a new comment, even though it is logically
575// part of the previous comment.
576.Ed
577.Sh FILES
578.Bl -tag -width ".Pa /etc/devd.conf" -compact
579.It Pa /etc/devd.conf
580The
581.Xr devd 8
582configuration file.
583.El
584.Sh EXAMPLES
585.Bd -literal
586#
587# This will catch link down events on the interfaces fxp0 and ath0
588#
589notify 0 {
590	match "system"			"IFNET";
591	match "subsystem"		"(fxp0|ath0)";
592	match "type"			"LINK_DOWN";
593	action "logger $subsystem is DOWN";
594};
595
596#
597# Match lid open/close events
598# These can be combined to a single event, by passing the
599# value of $notify to the external script.
600#
601notify 0 {
602	match "system"			"ACPI";
603	match "subsystem"		"Lid";
604	match "notify"			"0x00";
605	action "logger Lid closed, we can sleep now!";
606};
607
608notify 0 {
609	match "system"			"ACPI";
610	match "subsystem"		"Lid";
611	match "notify"			"0x01";
612	action "logger Lid opened, the sleeper must awaken!";
613};
614
615#
616# Match a USB device type
617#
618notify 0 {
619	match "system"			"USB";
620	match "subsystem"		"INTERFACE";
621	match "type"			"ATTACH";
622	match "intclass"		"0x0e";
623	action "logger USB video device attached";
624};
625
626#
627# Try to configure ath and wi devices with pccard_ether
628# as they are attached.
629#
630attach 0 {
631        device-name "(ath|wi)[0-9]+";
632        action "/etc/pccard_ether $device-name start";
633};
634
635#
636# Stop ath and wi devices as they are detached from
637# the system.
638#
639detach 0 {
640        device-name "(ath|wi)[0-9]+";
641        action "/etc/pccard_ether $device-name stop";
642};
643.Ed
644.Pp
645The installed
646.Pa /etc/devd.conf
647has many additional examples.
648.Sh SEE ALSO
649.Xr cam 4 ,
650.Xr coretemp 4 ,
651.Xr devfs 5 ,
652.Xr re_format 7 ,
653.Xr devd 8
654