chiark / gitweb /
re-enable failed event tracking
[elogind.git] / udev / udev.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <article>
6   <section>
7     <title>udev</title>
8     <refentry>
9       <refentryinfo>
10         <title>udev</title>
11         <date>August 2005</date>
12         <productname>udev</productname>
13       </refentryinfo>
14
15       <refmeta>
16         <refentrytitle>udev</refentrytitle>
17         <manvolnum>7</manvolnum>
18         <refmiscinfo class="version"></refmiscinfo>
19       </refmeta>
20
21       <refnamediv>
22         <refname>udev</refname>
23         <refpurpose>dynamic device management</refpurpose>
24       </refnamediv>
25
26       <refsect1><title>DESCRIPTION</title>
27         <para>udev provides a dynamic device directory containing only the files for
28         actually present devices. It creates or removes device node files in the
29         <filename>/dev</filename> directory, or it renames network interfaces.</para>
30
31         <para>Usually udev runs as <citerefentry><refentrytitle>udevd</refentrytitle>
32         <manvolnum>8</manvolnum></citerefentry> and receives uevents directly from the
33         kernel if a device is added or removed from the system.</para>
34
35         <para>If udev receives a device event, it matches its configured rules
36         against the available device attributes provided in sysfs to identify the device.
37         Rules that match may provide additional device information or specify a device
38         node name and multiple symlink names and instruct udev to run additional programs
39         as part of the device event handling.</para>
40       </refsect1>
41
42       <refsect1><title>CONFIGURATION</title>
43         <para>udev configuration files are placed in <filename>/etc/udev/</filename>
44         and <filename>/lib/udev/</filename>. All empty lines, or lines beginning with
45         '#' will be ignored.</para>
46
47         <refsect2><title>Configuration file</title>
48           <para>udev expects its main configuration file at <filename>/etc/udev/udev.conf</filename>.
49           It consists of a set of variables allowing the user to override default udev values.
50           The following variables can be set:</para>
51           <variablelist>
52             <varlistentry>
53               <term><option>udev_root</option></term>
54               <listitem>
55                 <para>Specifies where to place the device nodes in the filesystem.
56                 The default value is <filename>/dev</filename>.</para>
57               </listitem>
58             </varlistentry>
59
60             <varlistentry>
61               <term><option>udev_log</option></term>
62               <listitem>
63                 <para>The logging priority. Valid values are the numerical syslog priorities
64                 or their textual representations: <option>err</option>, <option>info</option>
65                 and <option>debug</option>.</para>
66               </listitem>
67             </varlistentry>
68           </variablelist>
69         </refsect2>
70
71         <refsect2><title>Rules files</title>
72           <para>The udev rules are read from the files located in the
73           default rules directory <filename>/lib/udev/rules.d/</filename>,
74           the custom rules directory <filename>/etc/udev/rules.d/</filename>
75           and the temporary rules directory <filename>/dev/.udev/rules.d/</filename>.
76           All rule files are sorted and processed in lexical order, regardless
77           in which of these directories they live.</para>
78
79           <para>Rule files are required to have a unique name, duplicate file names
80           are ignored. Files in <filename>/etc/udev/rules.d/</filename> have precedence
81           over files with the same name in <filename>/lib/udev/rules.d/</filename>. This
82           can be used to ignore a default rules file if needed.</para>
83
84           <para>Every line in the rules file contains at least one key value pair.
85           There are two kind of keys, match and assignment keys.
86           If all match keys are matching against its value, the rule gets applied and the
87           assign keys get the specified value assigned.</para>
88
89           <para>A matching rule may specify the name of the device node, add a symlink
90           pointing to the node, or run a specified program as part of the event handling.
91           If no matching rule is found, the default device node name is used.</para>
92
93           <para>A rule consists of a list of one or more key value pairs separated by
94           a comma. Each key has a distinct operation, depending on the used operator. Valid
95           operators are:</para>
96           <variablelist>
97             <varlistentry>
98               <term><option>==</option></term>
99               <listitem>
100                 <para>Compare for equality.</para>
101               </listitem>
102             </varlistentry>
103
104             <varlistentry>
105               <term><option>!=</option></term>
106               <listitem>
107                 <para>Compare for inequality.</para>
108               </listitem>
109             </varlistentry>
110
111             <varlistentry>
112               <term><option>=</option></term>
113               <listitem>
114                 <para>Assign a value to a key. Keys that represent a list, are reset
115                 and only this single value is assigned.</para>
116               </listitem>
117             </varlistentry>
118
119             <varlistentry>
120               <term><option>+=</option></term>
121               <listitem>
122                 <para>Add the value to a key that holds a list of entries.</para>
123               </listitem>
124             </varlistentry>
125
126             <varlistentry>
127               <term><option>:=</option></term>
128               <listitem>
129                 <para>Assign  a  value  to  a key finally; disallow any later changes,
130                 which may be used to prevent changes by any later rules.</para>
131               </listitem>
132             </varlistentry>
133           </variablelist>
134
135           <para>The following key names can be used to match against device properties.
136           Some of the keys also match against properties of the parent devices in sysfs,
137           not only the device that has generated the event. If multiple keys that match
138           a parent device are specified in a single rule, all these keys must match at
139           one and the same parent device.</para>
140           <variablelist>
141             <varlistentry>
142               <term><option>ACTION</option></term>
143               <listitem>
144                 <para>Match the name of the event action.</para>
145               </listitem>
146             </varlistentry>
147
148             <varlistentry>
149               <term><option>DEVPATH</option></term>
150               <listitem>
151                 <para>Match the devpath of the event device.</para>
152               </listitem>
153             </varlistentry>
154
155             <varlistentry>
156               <term><option>KERNEL</option></term>
157               <listitem>
158                 <para>Match the name of the event device.</para>
159               </listitem>
160             </varlistentry>
161
162             <varlistentry>
163               <term><option>NAME</option></term>
164               <listitem>
165                 <para>Match the name of the node or network interface. It can
166                 be used once the NAME key has been set in one of the preceding
167                 rules.</para>
168               </listitem>
169             </varlistentry>
170
171             <varlistentry>
172               <term><option>SUBSYSTEM</option></term>
173               <listitem>
174                 <para>Match the subsystem of the event device.</para>
175               </listitem>
176             </varlistentry>
177             <varlistentry>
178               <term><option>DRIVER</option></term>
179               <listitem>
180                 <para>Match the driver name of the event device. Only set for devices
181                 which are bound to a driver at the time the event is generated.</para>
182               </listitem>
183             </varlistentry>
184             <varlistentry>
185               <term><option>ATTR{<replaceable>filename</replaceable>}</option></term>
186               <listitem>
187                 <para>Match sysfs attribute values of the event device. Trailing
188                 whitespace in the attribute values is ignored, if the specified match
189                 value does not contain trailing whitespace itself.
190                 </para>
191               </listitem>
192             </varlistentry>
193
194             <varlistentry>
195               <term><option>KERNELS</option></term>
196               <listitem>
197                 <para>Search the devpath upwards for a matching device name.</para>
198               </listitem>
199             </varlistentry>
200
201             <varlistentry>
202               <term><option>SUBSYSTEMS</option></term>
203               <listitem>
204                 <para>Search the devpath upwards for a matching device subsystem name.</para>
205               </listitem>
206             </varlistentry>
207
208             <varlistentry>
209               <term><option>DRIVERS</option></term>
210               <listitem>
211                 <para>Search the devpath upwards for a matching device driver name.</para>
212               </listitem>
213             </varlistentry>
214
215             <varlistentry>
216               <term><option>ATTRS{<replaceable>filename</replaceable>}</option></term>
217               <listitem>
218                 <para>Search the devpath upwards for a device with matching sysfs attribute values.
219                 If multiple <option>ATTRS</option> matches are specified, all of them
220                 must match on the same device. Trailing whitespace in the attribute values is ignored,
221                 if the specified match value does not contain trailing whitespace itself.</para>
222               </listitem>
223             </varlistentry>
224
225             <varlistentry>
226               <term><option>ENV{<replaceable>key</replaceable>}</option></term>
227               <listitem>
228                 <para>Match against a device property value.</para>
229               </listitem>
230             </varlistentry>
231
232             <varlistentry>
233               <term><option>TEST{<replaceable>octal mode mask</replaceable>}</option></term>
234               <listitem>
235                 <para>Test the existence of a file. An octal mode mask can be specified
236                 if needed.</para>
237               </listitem>
238             </varlistentry>
239
240             <varlistentry>
241               <term><option>PROGRAM</option></term>
242               <listitem>
243                 <para>Execute a program. The key is true, if the program returns
244                 successfully. The device properties are made available to the
245                 executed program in the environment. The program's output printed to
246                 stdout, is available in the RESULT key.</para>
247               </listitem>
248             </varlistentry>
249
250             <varlistentry>
251               <term><option>RESULT</option></term>
252               <listitem>
253                 <para>Match the returned string of the last PROGRAM call. This key can
254                 be used in the same or in any later rule after a PROGRAM call.</para>
255               </listitem>
256             </varlistentry>
257           </variablelist>
258
259           <para>Most of the fields support a shell style pattern matching. The following
260           pattern characters are supported:</para>
261           <variablelist>
262             <varlistentry>
263               <term><option>*</option></term>
264               <listitem>
265                 <para>Matches zero, or any number of characters.</para>
266               </listitem>
267             </varlistentry>
268             <varlistentry>
269               <term><option>?</option></term>
270               <listitem>
271                 <para>Matches any single character.</para>
272               </listitem>
273             </varlistentry>
274             <varlistentry>
275               <term><option>[]</option></term>
276               <listitem>
277                 <para>Matches any single character specified within the brackets. For
278                 example, the pattern string 'tty[SR]' would match either 'ttyS' or 'ttyR'.
279                 Ranges are also supported within this match with the '-' character.
280                 For example, to match on the range of all digits, the pattern [0-9] would
281                 be used. If the first character following the '[' is a '!', any characters
282                 not enclosed are matched.</para>
283               </listitem>
284             </varlistentry>
285           </variablelist>
286
287           <para>The following keys can get values assigned:</para>
288           <variablelist>
289             <varlistentry>
290               <term><option>NAME</option></term>
291               <listitem>
292                 <para>The name of the node to be created, or the name the network interface
293                 should be renamed to.</para>
294               </listitem>
295             </varlistentry>
296
297             <varlistentry>
298               <term><option>SYMLINK</option></term>
299               <listitem>
300                 <para>The name of a symlink targeting the node. Every matching rule can add
301                 this value to the list of symlinks to be created along with the device  node.
302                 Multiple symlinks may be specified by separating the names by the space
303                 character.</para>
304               </listitem>
305             </varlistentry>
306
307             <varlistentry>
308               <term><option>OWNER, GROUP, MODE</option></term>
309               <listitem>
310                 <para>The permissions for the device node. Every specified value overwrites
311                 the compiled-in default value.</para>
312               </listitem>
313             </varlistentry>
314
315             <varlistentry>
316               <term><option>ATTR{<replaceable>key</replaceable>}</option></term>
317               <listitem>
318                 <para>The value that should be written to a sysfs attribute of the
319                 event device.</para>
320               </listitem>
321             </varlistentry>
322
323             <varlistentry>
324               <term><option>ENV{<replaceable>key</replaceable>}</option></term>
325               <listitem>
326                 <para>Set a device property value. Property names with a leading '.'
327                 are not stored in the database or exported to external tool or events.</para>
328               </listitem>
329             </varlistentry>
330
331             <varlistentry>
332               <term><option>RUN</option></term>
333               <listitem>
334                 <para>Add a program to the list of programs to be executed for a specific
335                 device. This can only be used for very short running tasks. Running an
336                 event process for a long period of time may block all further events for
337                 this or a dependent device. Long running tasks need to be immediately
338                 detached from the event process itself. If the option
339                 <option>RUN{<replaceable>record_failed</replaceable>}</option> is specified,
340                 and the executed program returns non-zero, the event will be marked as failed
341                 for a possible later handling.</para>
342                 <para>If the specified string starts with
343                 <option>socket:<replaceable>path</replaceable></option>, all current event
344                 values will be passed to the specified socket, as a message in the same
345                 format the kernel sends an uevent. If the first character of the specified path
346                 is an @ character, an abstract namespace socket is used, instead of an existing
347                 socket file.</para>
348               </listitem>
349             </varlistentry>
350
351             <varlistentry>
352               <term><option>LABEL</option></term>
353               <listitem>
354                 <para>Named label where a GOTO can jump to.</para>
355               </listitem>
356             </varlistentry>
357
358             <varlistentry>
359               <term><option>GOTO</option></term>
360               <listitem>
361                 <para>Jumps to the next LABEL with a matching name</para>
362               </listitem>
363             </varlistentry>
364
365             <varlistentry>
366               <term><option>IMPORT{<replaceable>type</replaceable>}</option></term>
367               <listitem>
368                 <para>Import a set of variables as device properties,
369                 depending on <replaceable>type</replaceable>:</para>
370                 <variablelist>
371                   <varlistentry>
372                     <term><option>program</option></term>
373                     <listitem>
374                       <para>Execute an external program specified as the assigned value and
375                       import its output, which must be in environment key format.</para>
376                     </listitem>
377                   </varlistentry>
378                   <varlistentry>
379                     <term><option>file</option></term>
380                     <listitem>
381                       <para>Import a text file specified as the assigned value, which must be in
382                       environment key format.</para>
383                     </listitem>
384                   </varlistentry>
385                   <varlistentry>
386                     <term><option>parent</option></term>
387                     <listitem>
388                       <para>Import the stored keys from the parent device by reading
389                       the database entry of the parent device. The value assigned to
390                       <option>IMPORT{parent}</option> is used as a filter of key names
391                       to import (with the same shell-style pattern matching used for
392                       comparisons).</para>
393                     </listitem>
394                   </varlistentry>
395                 </variablelist>
396                 <para>If no option is given, udev will choose between <option>program</option>
397                 and <option>file</option> based on the executable bit of the file
398                 permissions.</para>
399               </listitem>
400             </varlistentry>
401
402             <varlistentry>
403               <term><option>WAIT_FOR</option></term>
404               <listitem>
405                 <para>Wait for a file to become available.</para>
406               </listitem>
407             </varlistentry>
408
409             <varlistentry>
410               <term><option>OPTIONS</option></term>
411               <listitem>
412                 <para>Rule and device options:</para>
413                 <variablelist>
414                   <varlistentry>
415                     <term><option>last_rule</option></term>
416                     <listitem>
417                       <para>Stops further rules application. No later rules will have
418                       any effect.</para>
419                     </listitem>
420                   </varlistentry>
421                   <varlistentry>
422                     <term><option>ignore_device</option></term>
423                     <listitem>
424                       <para>Ignore this event completely.</para>
425                     </listitem>
426                   </varlistentry>
427                   <varlistentry>
428                     <term><option>ignore_remove</option></term>
429                     <listitem>
430                       <para>Do not remove the device node when the device goes away. This may be
431                       useful as a workaround for broken device drivers.</para>
432                     </listitem>
433                   </varlistentry>
434                   <varlistentry>
435                     <term><option>link_priority=<replaceable>value</replaceable></option></term>
436                     <listitem>
437                       <para>Specify the priority of the created symlinks. Devices with higher
438                       priorities overwrite existing symlinks of other devices. The default is 0.</para>
439                     </listitem>
440                   </varlistentry>
441                   <varlistentry>
442                     <term><option>all_partitions</option></term>
443                     <listitem>
444                       <para>Create the device nodes for all available partitions of a block device.
445                       This may be useful for removable media devices where media changes are not
446                       detected.</para>
447                     </listitem>
448                   </varlistentry>
449                   <varlistentry>
450                     <term><option>event_timeout=</option></term>
451                     <listitem>
452                       <para>Number of seconds an event will wait for operations to finish, before it
453                       will terminate itself.</para>
454                     </listitem>
455                   </varlistentry>
456                   <varlistentry>
457                     <term><option>string_escape=<replaceable>none|replace</replaceable></option></term>
458                     <listitem>
459                       <para>Usually control and other possibly unsafe characters are replaced
460                       in strings used for device naming. The mode of replacement can be specified
461                       with this option.</para>
462                     </listitem>
463                   </varlistentry>
464                   <varlistentry>
465                     <term><option>watch</option></term>
466                     <listitem>
467                       <para>Watch the device node with inotify, when closed after being opened for
468                       writing, a change uevent will be synthesised.</para>
469                     </listitem>
470                   </varlistentry>
471                 </variablelist>
472               </listitem>
473             </varlistentry>
474           </variablelist>
475
476           <para>The <option>NAME</option>, <option>SYMLINK</option>, <option>PROGRAM</option>,
477           <option>OWNER</option>, <option>GROUP</option>, <option>MODE</option>  and  <option>RUN</option>
478           fields support simple printf-like string substitutions. The <option>RUN</option>
479           format chars gets applied after all rules have been processed, right before the program
480           is executed. It allows the use of device properties set by earlier matching
481           rules. For all other fields, substitutions are applied while the individual rule is
482           being processed. The available substitutions are:</para>
483           <variablelist>
484             <varlistentry>
485               <term><option>$kernel</option>, <option>%k</option></term>
486               <listitem>
487                 <para>The kernel name for this device.</para>
488               </listitem>
489             </varlistentry>
490
491             <varlistentry>
492               <term><option>$number</option>, <option>%n</option></term>
493               <listitem>
494                 <para>The kernel number for this device. For example, 'sda3' has
495                 kernel number of '3'</para>
496               </listitem>
497             </varlistentry>
498
499             <varlistentry>
500               <term><option>$devpath</option>, <option>%p</option></term>
501               <listitem>
502                 <para>The devpath of the device.</para>
503               </listitem>
504             </varlistentry>
505
506             <varlistentry>
507               <term><option>$id</option>, <option>%b</option></term>
508               <listitem>
509                 <para>The name of the device matched while searching the devpath upwards for
510                   <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
511                 </para>
512               </listitem>
513             </varlistentry>
514
515             <varlistentry>
516               <term><option>$driver</option></term>
517               <listitem>
518                 <para>The driver name of the device matched while searching the devpath upwards for
519                   <option>SUBSYSTEMS</option>, <option>KERNELS</option>, <option>DRIVERS</option> and <option>ATTRS</option>.
520                 </para>
521               </listitem>
522             </varlistentry>
523
524             <varlistentry>
525               <term><option>$attr{<replaceable>file</replaceable>}</option>, <option>%s{<replaceable>file</replaceable>}</option></term>
526               <listitem>
527                 <para>The value of a sysfs attribute found at the device, where
528                 all keys of the rule have matched. If the matching device does not have
529                 such an attribute, follow the chain of parent devices and use the value
530                 of the first attribute that matches.
531                 If the attribute is a symlink, the last element of the symlink target is
532                 returned as the value.</para>
533               </listitem>
534             </varlistentry>
535
536             <varlistentry>
537               <term><option>$env{<replaceable>key</replaceable>}</option>, <option>%E{<replaceable>key</replaceable>}</option></term>
538               <listitem>
539                 <para>A device property value.</para>
540               </listitem>
541             </varlistentry>
542
543             <varlistentry>
544               <term><option>$major</option>, <option>%M</option></term>
545               <listitem>
546                 <para>The kernel major number for the device.</para>
547               </listitem>
548             </varlistentry>
549
550             <varlistentry>
551               <term><option>$minor</option>, <option>%m</option></term>
552               <listitem>
553                 <para>The kernel minor number for the device.</para>
554               </listitem>
555             </varlistentry>
556
557             <varlistentry>
558               <term><option>$result</option>, <option>%c</option></term>
559               <listitem>
560                 <para>The string returned by the external program requested with PROGRAM.
561                 A single part of the string, separated by a space character may be selected
562                 by specifying the part number as an attribute: <option>%c{N}</option>.
563                 If the number is followed by the '+' char this part plus all remaining parts
564                 of the result string are substituted: <option>%c{N+}</option></para>
565               </listitem>
566             </varlistentry>
567
568             <varlistentry>
569               <term><option>$parent</option>, <option>%P</option></term>
570               <listitem>
571                 <para>The node name of the parent device.</para>
572               </listitem>
573             </varlistentry>
574
575             <varlistentry>
576               <term><option>$name</option></term>
577               <listitem>
578                 <para>The current name of the device node. If not changed by a rule, it is the
579                 name of the kernel device.</para>
580               </listitem>
581             </varlistentry>
582
583             <varlistentry>
584               <term><option>$links</option></term>
585               <listitem>
586                 <para>The current list of symlinks, separated by a space character. The value is
587                 only set if an earlier rule assigned a value, or during a remove events.</para>
588               </listitem>
589             </varlistentry>
590
591             <varlistentry>
592               <term><option>$root</option>, <option>%r</option></term>
593               <listitem>
594                 <para>The udev_root value.</para>
595               </listitem>
596             </varlistentry>
597
598             <varlistentry>
599               <term><option>$sys</option>, <option>%S</option></term>
600               <listitem>
601                 <para>The sysfs mount point.</para>
602               </listitem>
603             </varlistentry>
604
605             <varlistentry>
606               <term><option>$tempnode</option>, <option>%N</option></term>
607               <listitem>
608                 <para>The name of a created temporary device node to provide access to
609                 the device from a external program before the real node is created.</para>
610               </listitem>
611             </varlistentry>
612
613             <varlistentry>
614               <term><option>%%</option></term>
615               <listitem>
616               <para>The '%' character itself.</para>
617               </listitem>
618             </varlistentry>
619
620             <varlistentry>
621               <term><option>$$</option></term>
622               <listitem>
623               <para>The '$' character itself.</para>
624               </listitem>
625             </varlistentry>
626           </variablelist>
627         </refsect2>
628       </refsect1>
629
630       <refsect1><title>AUTHOR</title>
631         <para>Written by Greg Kroah-Hartman <email>greg@kroah.com</email> and
632         Kay Sievers <email>kay.sievers@vrfy.org</email>. With much help from
633         Dan Stekloff and many others.</para>
634       </refsect1>
635
636       <refsect1>
637         <title>SEE ALSO</title>
638         <para><citerefentry>
639             <refentrytitle>udevd</refentrytitle><manvolnum>8</manvolnum>
640           </citerefentry>, 
641           <citerefentry>
642             <refentrytitle>udevadm</refentrytitle><manvolnum>8</manvolnum>
643         </citerefentry></para>
644       </refsect1>
645     </refentry>
646   </section>
647 </article>