| 1 |
<?xml version='1.0'?> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
|
| 5 |
<!-- |
| 6 |
SPDX-License-Identifier: LGPL-2.1-or-later |
| 7 |
Copyright © 2014 Jason St. John |
| 8 |
--> |
| 9 |
|
| 10 |
<refentry id="udev" xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 11 |
<refentryinfo> |
| 12 |
<title>udev</title> |
| 13 |
<productname>systemd</productname> |
| 14 |
</refentryinfo> |
| 15 |
|
| 16 |
<refmeta> |
| 17 |
<refentrytitle>udev</refentrytitle> |
| 18 |
<manvolnum>7</manvolnum> |
| 19 |
</refmeta> |
| 20 |
|
| 21 |
<refnamediv> |
| 22 |
<refname>udev</refname> |
| 23 |
<refpurpose>Dynamic device management</refpurpose> |
| 24 |
</refnamediv> |
| 25 |
|
| 26 |
<refsect1> |
| 27 |
<title>Description</title> |
| 28 |
<para>udev supplies the system software with device events, manages permissions |
| 29 |
of device nodes and may create additional symlinks in the <filename>/dev/</filename> |
| 30 |
directory, or renames network interfaces. The kernel usually just assigns unpredictable |
| 31 |
device names based on the order of discovery. Meaningful symlinks or network device |
| 32 |
names provide a way to reliably identify devices based on their properties or |
| 33 |
current configuration.</para> |
| 34 |
|
| 35 |
<para>The udev daemon, <citerefentry><refentrytitle>systemd-udevd.service</refentrytitle> |
| 36 |
<manvolnum>8</manvolnum></citerefentry>, receives device uevents directly from |
| 37 |
the kernel whenever a device is added or removed from the system, or it changes its |
| 38 |
state. When udev receives a device event, it matches its configured set of rules |
| 39 |
against various device attributes to identify the device. Rules that match may |
| 40 |
provide additional device information to be stored in the udev database or |
| 41 |
to be used to create meaningful symlink names.</para> |
| 42 |
|
| 43 |
<para>All device information udev processes is stored in the udev database and |
| 44 |
sent out to possible event subscribers. Access to all stored data and the event |
| 45 |
sources is provided by the library libudev.</para> |
| 46 |
</refsect1> |
| 47 |
|
| 48 |
<refsect1> |
| 49 |
<title>Rules Files</title> |
| 50 |
<para>The udev rules are read from the files located in the system rules directories |
| 51 |
<filename>/usr/lib/udev/rules.d</filename> and <filename>/usr/local/lib/udev/rules.d</filename>, the |
| 52 |
volatile runtime directory <filename>/run/udev/rules.d</filename> and the local administration |
| 53 |
directory <filename>/etc/udev/rules.d</filename>. All rules files are collectively sorted and |
| 54 |
processed in lexicographic order, regardless of the directories in which they live. However, files with |
| 55 |
identical filenames replace each other. Files in <filename>/etc/</filename> have the highest priority, |
| 56 |
files in <filename>/run/</filename> take precedence over files with the same name under |
| 57 |
<filename>/usr/</filename>. This can be used to override a system-supplied rules file with a local |
| 58 |
file if needed; a symlink in <filename>/etc/</filename> with the same name as a rules file in |
| 59 |
<filename>/usr/lib/</filename>, pointing to <filename>/dev/null</filename>, disables the rules file |
| 60 |
entirely. Rule files must have the extension <filename>.rules</filename>; other extensions are |
| 61 |
ignored.</para> |
| 62 |
|
| 63 |
<para>Every line in the rules file contains at least one key-value pair. |
| 64 |
Except for empty lines or lines beginning with <literal>#</literal>, which are ignored. |
| 65 |
There are two kinds of keys: match and assignment. |
| 66 |
If all match keys match against their values, the rule gets applied and the |
| 67 |
assignment keys get the specified values assigned.</para> |
| 68 |
|
| 69 |
<para>A matching rule may rename a network interface, add symlinks |
| 70 |
pointing to the device node, or run a specified program as part of |
| 71 |
the event handling.</para> |
| 72 |
|
| 73 |
<para>A rule consists of a comma-separated list of one or more key-operator-value expressions. |
| 74 |
Each expression has a distinct effect, depending on the key and operator used.</para> |
| 75 |
|
| 76 |
<refsect2> |
| 77 |
<title>Operators</title> |
| 78 |
<variablelist> |
| 79 |
<varlistentry> |
| 80 |
<term><literal>==</literal></term> |
| 81 |
<listitem> |
| 82 |
<para>Compare for equality. (The specified key has the specified value.)</para> |
| 83 |
</listitem> |
| 84 |
</varlistentry> |
| 85 |
|
| 86 |
<varlistentry> |
| 87 |
<term><literal>!=</literal></term> |
| 88 |
<listitem> |
| 89 |
<para>Compare for inequality. (The specified key does not have the specified value, or the |
| 90 |
specified key is not present at all.) |
| 91 |
</para> |
| 92 |
</listitem> |
| 93 |
</varlistentry> |
| 94 |
|
| 95 |
<varlistentry> |
| 96 |
<term><literal>=</literal></term> |
| 97 |
<listitem> |
| 98 |
<para>Assign a value to a key. Keys that represent a list are reset |
| 99 |
and only this single value is assigned.</para> |
| 100 |
</listitem> |
| 101 |
</varlistentry> |
| 102 |
|
| 103 |
<varlistentry> |
| 104 |
<term><literal>+=</literal></term> |
| 105 |
<listitem> |
| 106 |
<para>Add the value to a key that holds a list of entries.</para> |
| 107 |
</listitem> |
| 108 |
</varlistentry> |
| 109 |
|
| 110 |
<varlistentry> |
| 111 |
<term><literal>-=</literal></term> |
| 112 |
<listitem> |
| 113 |
<para>Remove the value from a key that holds a list of entries.</para> |
| 114 |
|
| 115 |
<xi:include href="version-info.xml" xpointer="v217"/> |
| 116 |
</listitem> |
| 117 |
</varlistentry> |
| 118 |
|
| 119 |
<varlistentry> |
| 120 |
<term><literal>:=</literal></term> |
| 121 |
<listitem> |
| 122 |
<para>Assign a value to a key finally; disallow any later changes.</para> |
| 123 |
|
| 124 |
<xi:include href="version-info.xml" xpointer="v247"/> |
| 125 |
</listitem> |
| 126 |
</varlistentry> |
| 127 |
</variablelist> |
| 128 |
</refsect2> |
| 129 |
|
| 130 |
<refsect2> |
| 131 |
<title>Values</title> |
| 132 |
<para>Values are written as double quoted strings, such as ("string"). |
| 133 |
To include a quotation mark (") in the value, precede it by a backslash (\"). |
| 134 |
Any other occurrences of a backslash followed by a character are not unescaped. |
| 135 |
That is, "\t\n" is treated as four characters: |
| 136 |
backslash, lowercase t, backslash, lowercase n.</para> |
| 137 |
|
| 138 |
<para>The string can be prefixed with a lowercase e (e"string\n") to mark the string as |
| 139 |
C-style escaped, see |
| 140 |
<ulink url="https://en.wikipedia.org/wiki/Escape_sequences_in_C#Table_of_escape_sequences">Escape sequences in C</ulink>. |
| 141 |
For example, e"string\n" is parsed as 7 characters: 6 lowercase letters and a newline. |
| 142 |
This can be useful for writing special characters when a kernel driver requires them.</para> |
| 143 |
|
| 144 |
<para>The string can be prefixed with a lowercase i (i"string") to mark that the string or pattern |
| 145 |
will match case-insensitively. For example, i"foo" will match |
| 146 |
<literal>foo</literal>, <literal>FOO</literal>, <literal>FoO</literal> and so on. The prefix can be |
| 147 |
used only for match (<literal>==</literal>) or unmatch (<literal>!=</literal>) rules, e.g. |
| 148 |
<varname>ATTR{foo}==i"abcd"</varname>.</para> |
| 149 |
|
| 150 |
<para>Please note that <constant>NUL</constant> is not allowed in either string variant.</para> |
| 151 |
</refsect2> |
| 152 |
|
| 153 |
<refsect2> |
| 154 |
<title>Keys</title> |
| 155 |
<para>The following key names can be used to match against device properties. |
| 156 |
Some of the keys also match against properties of the parent devices in sysfs, |
| 157 |
not only the device that has generated the event. If multiple keys that match |
| 158 |
a parent device are specified in a single rule, all these keys must match at |
| 159 |
one and the same parent device.</para> |
| 160 |
<variablelist class='udev-directives'> |
| 161 |
<varlistentry> |
| 162 |
<term><varname>ACTION</varname></term> |
| 163 |
<listitem> |
| 164 |
<para>Match the name of the event action.</para> |
| 165 |
</listitem> |
| 166 |
</varlistentry> |
| 167 |
|
| 168 |
<varlistentry> |
| 169 |
<term><varname>DEVPATH</varname></term> |
| 170 |
<listitem> |
| 171 |
<para>Match the devpath of the event device.</para> |
| 172 |
</listitem> |
| 173 |
</varlistentry> |
| 174 |
|
| 175 |
<varlistentry> |
| 176 |
<term><varname>KERNEL</varname></term> |
| 177 |
<listitem> |
| 178 |
<para>Match the name of the event device.</para> |
| 179 |
</listitem> |
| 180 |
</varlistentry> |
| 181 |
|
| 182 |
<varlistentry> |
| 183 |
<term><varname>KERNELS</varname></term> |
| 184 |
<listitem> |
| 185 |
<para>Search the devpath upwards for a matching device name.</para> |
| 186 |
</listitem> |
| 187 |
</varlistentry> |
| 188 |
|
| 189 |
<varlistentry> |
| 190 |
<term><varname>NAME</varname></term> |
| 191 |
<listitem> |
| 192 |
<para>Match the name of a network interface. It can be used once the |
| 193 |
NAME key has been set in one of the preceding rules.</para> |
| 194 |
</listitem> |
| 195 |
</varlistentry> |
| 196 |
|
| 197 |
<varlistentry> |
| 198 |
<term><varname>SYMLINK</varname></term> |
| 199 |
<listitem> |
| 200 |
<para>Match the name of a symlink targeting the node. It can be used once a SYMLINK key has |
| 201 |
been set in one of the preceding rules. There may be multiple symlinks; only one needs to |
| 202 |
match. If the operator is <literal>!=</literal>, the token returns true only if there is no |
| 203 |
symlink matched.</para> |
| 204 |
</listitem> |
| 205 |
</varlistentry> |
| 206 |
|
| 207 |
<varlistentry> |
| 208 |
<term><varname>SUBSYSTEM</varname></term> |
| 209 |
<listitem> |
| 210 |
<para>Match the subsystem of the event device.</para> |
| 211 |
</listitem> |
| 212 |
</varlistentry> |
| 213 |
|
| 214 |
<varlistentry> |
| 215 |
<term><varname>SUBSYSTEMS</varname></term> |
| 216 |
<listitem> |
| 217 |
<para>Search the devpath upwards for a matching device subsystem name.</para> |
| 218 |
</listitem> |
| 219 |
</varlistentry> |
| 220 |
|
| 221 |
<varlistentry> |
| 222 |
<term><varname>DRIVER</varname></term> |
| 223 |
<listitem> |
| 224 |
<para>Match the driver name of the event device. Only set this key for devices |
| 225 |
which are bound to a driver at the time the event is generated.</para> |
| 226 |
</listitem> |
| 227 |
</varlistentry> |
| 228 |
|
| 229 |
<varlistentry> |
| 230 |
<term><varname>DRIVERS</varname></term> |
| 231 |
<listitem> |
| 232 |
<para>Search the devpath upwards for a matching device driver name.</para> |
| 233 |
</listitem> |
| 234 |
</varlistentry> |
| 235 |
|
| 236 |
<varlistentry> |
| 237 |
<term><varname>ATTR{<replaceable>filename</replaceable>}</varname></term> |
| 238 |
<listitem> |
| 239 |
<para>Match sysfs attribute value of the event device.</para> |
| 240 |
|
| 241 |
<para>Trailing whitespace in the attribute values is ignored unless the specified match value |
| 242 |
itself contains trailing whitespace.</para> |
| 243 |
</listitem> |
| 244 |
</varlistentry> |
| 245 |
|
| 246 |
<varlistentry> |
| 247 |
<term><varname>ATTRS{<replaceable>filename</replaceable>}</varname></term> |
| 248 |
<listitem> |
| 249 |
<para>Search the devpath upwards for a device with matching sysfs attribute values. If |
| 250 |
multiple <varname>ATTRS</varname> matches are specified, all of them must match on the same |
| 251 |
device.</para> |
| 252 |
|
| 253 |
<para>Trailing whitespace in the attribute values is ignored unless the specified match value |
| 254 |
itself contains trailing whitespace.</para> |
| 255 |
</listitem> |
| 256 |
</varlistentry> |
| 257 |
|
| 258 |
<varlistentry> |
| 259 |
<term><varname>SYSCTL{<replaceable>kernel parameter</replaceable>}</varname></term> |
| 260 |
<listitem> |
| 261 |
<para>Match a kernel parameter value.</para> |
| 262 |
|
| 263 |
<xi:include href="version-info.xml" xpointer="v240"/> |
| 264 |
</listitem> |
| 265 |
</varlistentry> |
| 266 |
|
| 267 |
<varlistentry> |
| 268 |
<term><varname>ENV{<replaceable>key</replaceable>}</varname></term> |
| 269 |
<listitem> |
| 270 |
<para>Match against a device property value.</para> |
| 271 |
</listitem> |
| 272 |
</varlistentry> |
| 273 |
|
| 274 |
<varlistentry> |
| 275 |
<term><varname>CONST{<replaceable>key</replaceable>}</varname></term> |
| 276 |
<listitem> |
| 277 |
<para>Match against a system-wide constant. Supported keys are:</para> |
| 278 |
<variablelist> |
| 279 |
<varlistentry> |
| 280 |
<term><literal>arch</literal></term> |
| 281 |
<listitem> |
| 282 |
<para>System's architecture. See <option>ConditionArchitecture=</option> in |
| 283 |
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 284 |
for possible values.</para> |
| 285 |
|
| 286 |
<xi:include href="version-info.xml" xpointer="v244"/> |
| 287 |
</listitem> |
| 288 |
</varlistentry> |
| 289 |
<varlistentry> |
| 290 |
<term><literal>virt</literal></term> |
| 291 |
<listitem> |
| 292 |
<para>System's virtualization environment. See |
| 293 |
<citerefentry><refentrytitle>systemd-detect-virt</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 294 |
for possible values.</para> |
| 295 |
|
| 296 |
<xi:include href="version-info.xml" xpointer="v244"/> |
| 297 |
</listitem> |
| 298 |
</varlistentry> |
| 299 |
<varlistentry> |
| 300 |
<term><literal>cvm</literal></term> |
| 301 |
<listitem> |
| 302 |
<para>System's confidential virtualization technology. See |
| 303 |
<citerefentry><refentrytitle>systemd-detect-virt</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 304 |
for possible values.</para> |
| 305 |
|
| 306 |
<xi:include href="version-info.xml" xpointer="v254"/> |
| 307 |
</listitem> |
| 308 |
</varlistentry> |
| 309 |
</variablelist> |
| 310 |
<para>Unknown keys will never match.</para> |
| 311 |
|
| 312 |
<xi:include href="version-info.xml" xpointer="v244"/> |
| 313 |
</listitem> |
| 314 |
</varlistentry> |
| 315 |
|
| 316 |
<varlistentry> |
| 317 |
<term><varname>TAG</varname></term> |
| 318 |
<listitem> |
| 319 |
<para>Match against one of device tags. It can be used once a TAG key has been set in one of |
| 320 |
the preceding rules. There may be multiple tags; only one needs to match. If the operator is |
| 321 |
<literal>!=</literal>, the token returns true only if there is no tag matched.</para> |
| 322 |
</listitem> |
| 323 |
</varlistentry> |
| 324 |
|
| 325 |
<varlistentry> |
| 326 |
<term><varname>TAGS</varname></term> |
| 327 |
<listitem> |
| 328 |
<para>Search the devpath upwards for a device with matching tag. If the operator is |
| 329 |
<literal>!=</literal>, the token returns true only if there is no tag matched.</para> |
| 330 |
</listitem> |
| 331 |
</varlistentry> |
| 332 |
|
| 333 |
<varlistentry> |
| 334 |
<term><varname>TEST{<replaceable>octal mode mask</replaceable>}</varname></term> |
| 335 |
<listitem> |
| 336 |
<para>Test the existence of a file. An octal mode mask can be specified |
| 337 |
if needed.</para> |
| 338 |
</listitem> |
| 339 |
</varlistentry> |
| 340 |
|
| 341 |
<varlistentry> |
| 342 |
<term><varname>PROGRAM</varname></term> |
| 343 |
<listitem> |
| 344 |
<para>Execute a program to determine whether there is a match; the key is true if the program |
| 345 |
returns successfully. The device properties are made available to the executed program in the |
| 346 |
environment. The program's standard output is available in the <varname>RESULT</varname> |
| 347 |
key.</para> |
| 348 |
|
| 349 |
<para>This can only be used for very short-running foreground tasks. For details, see |
| 350 |
<varname>RUN</varname>.</para> |
| 351 |
|
| 352 |
<para>Note that multiple <varname>PROGRAM</varname> keys may be specified in one rule, and |
| 353 |
<literal>=</literal>, <literal>:=</literal>, and <literal>+=</literal> have the same effect as |
| 354 |
<literal>==</literal>.</para> |
| 355 |
</listitem> |
| 356 |
</varlistentry> |
| 357 |
|
| 358 |
<varlistentry> |
| 359 |
<term><varname>RESULT</varname></term> |
| 360 |
<listitem> |
| 361 |
<para>Match the returned string of the last <varname>PROGRAM</varname> call. |
| 362 |
This key can be used in the same or in any later rule after a |
| 363 |
<varname>PROGRAM</varname> call.</para> |
| 364 |
</listitem> |
| 365 |
</varlistentry> |
| 366 |
</variablelist> |
| 367 |
|
| 368 |
<para>Most of the fields support shell glob pattern matching and |
| 369 |
alternate patterns. The following special characters are supported:</para> |
| 370 |
<variablelist> |
| 371 |
<varlistentry> |
| 372 |
<term><literal>*</literal></term> |
| 373 |
<listitem> |
| 374 |
<para>Matches zero or more characters.</para> |
| 375 |
</listitem> |
| 376 |
</varlistentry> |
| 377 |
<varlistentry> |
| 378 |
<term><literal>?</literal></term> |
| 379 |
<listitem> |
| 380 |
<para>Matches any single character.</para> |
| 381 |
</listitem> |
| 382 |
</varlistentry> |
| 383 |
<varlistentry> |
| 384 |
<term><literal>[]</literal></term> |
| 385 |
<listitem> |
| 386 |
<para>Matches any single character specified within the brackets. For |
| 387 |
example, the pattern string <literal>tty[SR]</literal> |
| 388 |
would match either <literal>ttyS</literal> or <literal>ttyR</literal>. |
| 389 |
Ranges are also supported via the <literal>-</literal> character. |
| 390 |
For example, to match on the range of all digits, the pattern |
| 391 |
<literal>[0-9]</literal> could be used. If the first character |
| 392 |
following the <literal>[</literal> is a <literal>!</literal>, |
| 393 |
any characters not enclosed are matched.</para> |
| 394 |
</listitem> |
| 395 |
</varlistentry> |
| 396 |
<varlistentry> |
| 397 |
<term><literal>|</literal></term> |
| 398 |
<listitem> |
| 399 |
<para>Separates alternative patterns. For example, the pattern string |
| 400 |
<literal>abc|x*</literal> would match either <literal>abc</literal> |
| 401 |
or <literal>x*</literal>.</para> |
| 402 |
|
| 403 |
<xi:include href="version-info.xml" xpointer="v217"/> |
| 404 |
</listitem> |
| 405 |
</varlistentry> |
| 406 |
</variablelist> |
| 407 |
|
| 408 |
<para>The following keys can get values assigned:</para> |
| 409 |
<variablelist class='udev-directives'> |
| 410 |
<varlistentry> |
| 411 |
<term><varname>NAME</varname></term> |
| 412 |
<listitem> |
| 413 |
<para>The name to use for a network interface. See |
| 414 |
<citerefentry><refentrytitle>systemd.link</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 415 |
for a higher-level mechanism for setting the interface name. |
| 416 |
The name of a device node cannot be changed by udev, only additional |
| 417 |
symlinks can be created.</para> |
| 418 |
</listitem> |
| 419 |
</varlistentry> |
| 420 |
|
| 421 |
<varlistentry> |
| 422 |
<term><varname>SYMLINK</varname></term> |
| 423 |
<listitem> |
| 424 |
<para>The name of a symlink targeting the node. Every matching rule adds |
| 425 |
this value to the list of symlinks to be created.</para> |
| 426 |
<para>The set of characters to name a symlink is limited. Allowed |
| 427 |
characters are <literal>0-9A-Za-z#+-.:=@_/</literal>, valid UTF-8 character |
| 428 |
sequences, and <literal>\x00</literal> hex encoding. All other |
| 429 |
characters are replaced by a <literal>_</literal> character.</para> |
| 430 |
<para>Multiple symlinks may be specified by separating the names by the |
| 431 |
space character. In case multiple devices claim the same name, the link |
| 432 |
always points to the device with the highest link_priority. If the current |
| 433 |
device goes away, the links are re-evaluated and the device with the |
| 434 |
next highest link_priority becomes the owner of the link. If no |
| 435 |
link_priority is specified, the order of the devices (and which one of |
| 436 |
them owns the link) is undefined.</para> |
| 437 |
<para>Symlink names must never conflict with the kernel's default device |
| 438 |
node names, as that would result in unpredictable behavior. |
| 439 |
</para> |
| 440 |
</listitem> |
| 441 |
</varlistentry> |
| 442 |
|
| 443 |
<varlistentry> |
| 444 |
<term><varname>OWNER</varname>, <varname>GROUP</varname>, <varname>MODE</varname></term> |
| 445 |
<listitem> |
| 446 |
<para>The permissions for the device node. Every specified value overrides |
| 447 |
the compiled-in default value.</para> |
| 448 |
</listitem> |
| 449 |
</varlistentry> |
| 450 |
|
| 451 |
<varlistentry> |
| 452 |
<term><varname>SECLABEL{<replaceable>module</replaceable>}</varname></term> |
| 453 |
<listitem> |
| 454 |
<para>Applies the specified Linux Security Module label to the device node.</para> |
| 455 |
|
| 456 |
<xi:include href="version-info.xml" xpointer="v209"/> |
| 457 |
</listitem> |
| 458 |
</varlistentry> |
| 459 |
|
| 460 |
<varlistentry> |
| 461 |
<term><varname>ATTR{<replaceable>key</replaceable>}</varname></term> |
| 462 |
<listitem> |
| 463 |
<para>The value that should be written to a sysfs attribute of the |
| 464 |
event device.</para> |
| 465 |
</listitem> |
| 466 |
</varlistentry> |
| 467 |
|
| 468 |
<varlistentry> |
| 469 |
<term><varname>SYSCTL{<replaceable>kernel parameter</replaceable>}</varname></term> |
| 470 |
<listitem> |
| 471 |
<para>The value that should be written to kernel parameter.</para> |
| 472 |
|
| 473 |
<xi:include href="version-info.xml" xpointer="v220"/> |
| 474 |
</listitem> |
| 475 |
</varlistentry> |
| 476 |
|
| 477 |
<varlistentry> |
| 478 |
<term><varname>ENV{<replaceable>key</replaceable>}</varname></term> |
| 479 |
<listitem> |
| 480 |
<para>Set a device property value. Property names with a leading <literal>.</literal> |
| 481 |
are neither stored in the database nor exported to events or |
| 482 |
external tools (run by, for example, the <varname>PROGRAM</varname> |
| 483 |
match key).</para> |
| 484 |
</listitem> |
| 485 |
</varlistentry> |
| 486 |
|
| 487 |
<varlistentry> |
| 488 |
<term><varname>TAG</varname></term> |
| 489 |
<listitem> |
| 490 |
<para>Attach a tag to a device. This is used to filter events for users |
| 491 |
of libudev's monitor functionality, or to enumerate a group of tagged |
| 492 |
devices. The implementation can only work efficiently if only a few |
| 493 |
tags are attached to a device. It is only meant to be used in |
| 494 |
contexts with specific device filter requirements, and not as a |
| 495 |
general-purpose flag. Excessive use might result in inefficient event |
| 496 |
handling.</para> |
| 497 |
</listitem> |
| 498 |
</varlistentry> |
| 499 |
|
| 500 |
<varlistentry> |
| 501 |
<term><varname>RUN{<replaceable>type</replaceable>}</varname></term> |
| 502 |
<listitem> |
| 503 |
<para>Specify a program to be executed after processing of all the rules for the event. With |
| 504 |
<literal>+=</literal>, this invocation is added to the list, and with <literal>=</literal> or |
| 505 |
<literal>:=</literal>, it replaces any previous contents of the list. Please note that both |
| 506 |
<literal>program</literal> and <literal>builtin</literal> types described below share a common |
| 507 |
list, so clearing the list with <literal>:=</literal> and <literal>=</literal> affects both |
| 508 |
types.</para> |
| 509 |
|
| 510 |
<para><replaceable>type</replaceable> may be:</para> |
| 511 |
<variablelist> |
| 512 |
<varlistentry> |
| 513 |
<term><literal>program</literal></term> |
| 514 |
<listitem> |
| 515 |
<para>Execute an external program specified as the assigned |
| 516 |
value. If no absolute path is given, the program is expected |
| 517 |
to live in <filename>/usr/lib/udev</filename>; otherwise, the |
| 518 |
absolute path must be specified.</para> |
| 519 |
<para>This is the default if no <replaceable>type</replaceable> |
| 520 |
is specified.</para> |
| 521 |
</listitem> |
| 522 |
</varlistentry> |
| 523 |
<varlistentry> |
| 524 |
<term><literal>builtin</literal></term> |
| 525 |
<listitem> |
| 526 |
<para>As <varname>program</varname>, but use one of the |
| 527 |
built-in programs rather than an external one.</para> |
| 528 |
|
| 529 |
<xi:include href="version-info.xml" xpointer="v199"/> |
| 530 |
</listitem> |
| 531 |
</varlistentry> |
| 532 |
</variablelist> |
| 533 |
|
| 534 |
<para>The program name and following arguments are separated by spaces. Single quotes can be |
| 535 |
used to specify arguments with spaces.</para> |
| 536 |
|
| 537 |
<para>This can only be used for very short-running foreground tasks. Running an event process for |
| 538 |
a long period of time may block all further events for this or a dependent device.</para> |
| 539 |
|
| 540 |
<para>Note that running programs that access the network or mount/unmount filesystems is not |
| 541 |
allowed inside of udev rules, due to the default sandbox that is enforced on |
| 542 |
<filename>systemd-udevd.service</filename>.</para> |
| 543 |
|
| 544 |
<para>Starting daemons or other long-running processes is not allowed; the forked processes, |
| 545 |
detached or not, will be unconditionally killed after the event handling has finished. In order |
| 546 |
to activate long-running processes from udev rules, provide a service unit and pull it in from a |
| 547 |
udev device using the <varname>SYSTEMD_WANTS</varname> device property. See |
| 548 |
<citerefentry><refentrytitle>systemd.device</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 549 |
for details.</para> |
| 550 |
</listitem> |
| 551 |
</varlistentry> |
| 552 |
|
| 553 |
<varlistentry> |
| 554 |
<term><varname>LABEL</varname></term> |
| 555 |
<listitem> |
| 556 |
<para>A named label to which a <varname>GOTO</varname> may jump.</para> |
| 557 |
</listitem> |
| 558 |
</varlistentry> |
| 559 |
|
| 560 |
<varlistentry> |
| 561 |
<term><varname>GOTO</varname></term> |
| 562 |
<listitem> |
| 563 |
<para>Jumps to the next <varname>LABEL</varname> with a matching name.</para> |
| 564 |
</listitem> |
| 565 |
</varlistentry> |
| 566 |
|
| 567 |
<varlistentry> |
| 568 |
<term><varname>IMPORT{<replaceable>type</replaceable>}</varname></term> |
| 569 |
<listitem> |
| 570 |
<para>Import a set of variables as device properties, depending on |
| 571 |
<replaceable>type</replaceable>:</para> |
| 572 |
|
| 573 |
<variablelist> |
| 574 |
<varlistentry> |
| 575 |
<term><literal>program</literal></term> |
| 576 |
<listitem> |
| 577 |
<para>Execute an external program specified as the assigned |
| 578 |
value and, if it returns successfully, |
| 579 |
import its output, which must be in environment key |
| 580 |
format. Path specification, command/argument separation, |
| 581 |
and quoting work like in <varname>RUN</varname>.</para> |
| 582 |
|
| 583 |
<xi:include href="version-info.xml" xpointer="v199"/> |
| 584 |
</listitem> |
| 585 |
</varlistentry> |
| 586 |
<varlistentry> |
| 587 |
<term><literal>builtin</literal></term> |
| 588 |
<listitem> |
| 589 |
<para>Similar to <literal>program</literal>, but use one of the |
| 590 |
built-in programs rather than an external one.</para> |
| 591 |
|
| 592 |
<xi:include href="version-info.xml" xpointer="v199"/> |
| 593 |
</listitem> |
| 594 |
</varlistentry> |
| 595 |
<varlistentry> |
| 596 |
<term><literal>file</literal></term> |
| 597 |
<listitem> |
| 598 |
<para>Import a text file specified as the assigned value, the content |
| 599 |
of which must be in environment key format.</para> |
| 600 |
</listitem> |
| 601 |
</varlistentry> |
| 602 |
<varlistentry> |
| 603 |
<term><literal>db</literal></term> |
| 604 |
<listitem> |
| 605 |
<para>Import a single property specified as the assigned value from the |
| 606 |
current device database. This works only if the database is already populated |
| 607 |
by an earlier event.</para> |
| 608 |
</listitem> |
| 609 |
</varlistentry> |
| 610 |
<varlistentry> |
| 611 |
<term><literal>cmdline</literal></term> |
| 612 |
<listitem> |
| 613 |
<para>Import a single property from the kernel command line. For simple flags |
| 614 |
the value of the property is set to <literal>1</literal>.</para> |
| 615 |
</listitem> |
| 616 |
</varlistentry> |
| 617 |
<varlistentry> |
| 618 |
<term><literal>parent</literal></term> |
| 619 |
<listitem> |
| 620 |
<para>Import the stored keys from the parent device by reading |
| 621 |
the database entry of the parent device. The value assigned to |
| 622 |
<option>IMPORT{parent}</option> is used as a filter of key names |
| 623 |
to import (with the same shell glob pattern matching used for |
| 624 |
comparisons).</para> |
| 625 |
</listitem> |
| 626 |
</varlistentry> |
| 627 |
</variablelist> |
| 628 |
|
| 629 |
<para>This can only be used for very short-running foreground tasks. For details see |
| 630 |
<option>RUN</option>.</para> |
| 631 |
|
| 632 |
<para>Note that multiple <varname>IMPORT{}</varname> keys may be specified in one rule, and |
| 633 |
<literal>=</literal>, <literal>:=</literal>, and <literal>+=</literal> have the same effect as |
| 634 |
<literal>==</literal>. The key is true if the import is successful, unless <literal>!=</literal> |
| 635 |
is used as the operator which causes the key to be true if the import failed.</para> |
| 636 |
</listitem> |
| 637 |
</varlistentry> |
| 638 |
|
| 639 |
<varlistentry> |
| 640 |
<term><varname>OPTIONS</varname></term> |
| 641 |
<listitem> |
| 642 |
<para>Rule and device options:</para> |
| 643 |
<variablelist class='udev-directives'> |
| 644 |
<varlistentry> |
| 645 |
<term><option>link_priority=<replaceable>value</replaceable></option></term> |
| 646 |
<listitem> |
| 647 |
<para>Specify the priority of the created symlinks. Devices with higher |
| 648 |
priorities overwrite existing symlinks of other devices. The default is 0.</para> |
| 649 |
</listitem> |
| 650 |
</varlistentry> |
| 651 |
<varlistentry> |
| 652 |
<term><option>string_escape=<replaceable>none|replace</replaceable></option></term> |
| 653 |
<listitem> |
| 654 |
<para>When <literal>replace</literal>, possibly unsafe characters in strings |
| 655 |
assigned to <varname>NAME</varname>, <varname>SYMLINK</varname>, and |
| 656 |
<varname>ENV{<replaceable>key</replaceable>}</varname> are replaced. When |
| 657 |
<literal>none</literal>, no replacement is performed. When unset, the replacement |
| 658 |
is performed for <varname>NAME</varname>, <varname>SYMLINK</varname>, but not for |
| 659 |
<varname>ENV{<replaceable>key</replaceable>}</varname>. Defaults to unset.</para> |
| 660 |
</listitem> |
| 661 |
</varlistentry> |
| 662 |
<varlistentry> |
| 663 |
<term><option>static_node=</option></term> |
| 664 |
<listitem> |
| 665 |
<para>Apply the permissions specified in this rule to the |
| 666 |
static device node with the specified name. Also, for every |
| 667 |
tag specified in this rule, create a symlink |
| 668 |
in the directory |
| 669 |
<filename>/run/udev/static_node-tags/<replaceable>tag</replaceable></filename> |
| 670 |
pointing at the static device node with the specified name. |
| 671 |
Static device node creation is performed by systemd-tmpfiles |
| 672 |
before systemd-udevd is started. The static nodes might not |
| 673 |
have a corresponding kernel device; they are used to trigger |
| 674 |
automatic kernel module loading when they are accessed.</para> |
| 675 |
</listitem> |
| 676 |
</varlistentry> |
| 677 |
<varlistentry> |
| 678 |
<term><option>watch</option></term> |
| 679 |
<listitem> |
| 680 |
<para>Watch the device node with inotify; when the node is |
| 681 |
closed after being opened for writing, a change uevent is |
| 682 |
synthesized.</para> |
| 683 |
</listitem> |
| 684 |
</varlistentry> |
| 685 |
<varlistentry> |
| 686 |
<term><option>nowatch</option></term> |
| 687 |
<listitem> |
| 688 |
<para>Disable the watching of a device node with inotify.</para> |
| 689 |
</listitem> |
| 690 |
</varlistentry> |
| 691 |
<varlistentry> |
| 692 |
<term><option>db_persist</option></term> |
| 693 |
<listitem> |
| 694 |
<para>Set the flag (sticky bit) on the udev database entry of the event device. Device |
| 695 |
properties are then kept in the database even when <command>udevadm info |
| 696 |
--cleanup-db</command> is called. This option can be useful in certain cases |
| 697 |
(e.g. Device Mapper devices) for persisting device state on the transition from |
| 698 |
initrd.</para> |
| 699 |
|
| 700 |
<xi:include href="version-info.xml" xpointer="v241"/> |
| 701 |
</listitem> |
| 702 |
</varlistentry> |
| 703 |
<varlistentry> |
| 704 |
<term><option>log_level=<replaceable>level</replaceable></option></term> |
| 705 |
<listitem> |
| 706 |
<para>Takes a log level name like <literal>debug</literal> or |
| 707 |
<literal>info</literal>, or a special value <literal>reset</literal>. When a log |
| 708 |
level name is specified, the maximum log level is changed to that level. When |
| 709 |
<literal>reset</literal> is set, then the previously specified log level is |
| 710 |
revoked. Defaults to the log level of the main process of |
| 711 |
<command>systemd-udevd</command>.</para> |
| 712 |
<para>This may be useful when debugging events for certain devices. Note that the |
| 713 |
log level is applied when the line including this rule is processed. So, for |
| 714 |
debugging, it is recommended that this is specified at earlier place, e.g., the |
| 715 |
first line of <filename>00-debug.rules</filename>.</para> |
| 716 |
<para>Example for debugging uevent processing for network interfaces: |
| 717 |
<programlisting># /etc/udev/rules.d/00-debug-net.rules |
| 718 |
SUBSYSTEM=="net", OPTIONS="log_level=debug"</programlisting></para> |
| 719 |
|
| 720 |
<xi:include href="version-info.xml" xpointer="v248"/> |
| 721 |
</listitem> |
| 722 |
</varlistentry> |
| 723 |
<varlistentry> |
| 724 |
<term><option>dump</option></term> |
| 725 |
<listitem> |
| 726 |
<para>Dump the status of the event currently processing. It may be useful for debugging |
| 727 |
udev rules by inserting this option.</para> |
| 728 |
|
| 729 |
<xi:include href="version-info.xml" xpointer="v258"/> |
| 730 |
</listitem> |
| 731 |
</varlistentry> |
| 732 |
<varlistentry> |
| 733 |
<term><option>dump-json</option></term> |
| 734 |
<listitem> |
| 735 |
<para>Similar to <option>dump</option>, but dump the status of the event in JSON format.</para> |
| 736 |
|
| 737 |
<xi:include href="version-info.xml" xpointer="v259"/> |
| 738 |
</listitem> |
| 739 |
</varlistentry> |
| 740 |
</variablelist> |
| 741 |
</listitem> |
| 742 |
</varlistentry> |
| 743 |
</variablelist> |
| 744 |
|
| 745 |
<para>The <varname>ENV</varname>, <varname>GROUP</varname>, |
| 746 |
<varname>MODE</varname>, <varname>NAME</varname>, |
| 747 |
<varname>OWNER</varname>, <varname>PROGRAM</varname>, |
| 748 |
<varname>RUN</varname>, <varname>SECLABEL</varname>, and |
| 749 |
<varname>SYMLINK</varname> fields support simple string substitutions. |
| 750 |
The <varname>RUN</varname> substitutions are performed after all rules |
| 751 |
have been processed, right before the program is executed, allowing for |
| 752 |
the use of device properties set by earlier matching rules. For all |
| 753 |
other fields, substitutions are performed while the individual rule is |
| 754 |
being processed. The available substitutions are:</para> |
| 755 |
<variablelist class='udev-directives'> |
| 756 |
<varlistentry> |
| 757 |
<term><option>$kernel</option>, <option>%k</option></term> |
| 758 |
<listitem> |
| 759 |
<para>The kernel name for this device.</para> |
| 760 |
</listitem> |
| 761 |
</varlistentry> |
| 762 |
|
| 763 |
<varlistentry> |
| 764 |
<term><option>$number</option>, <option>%n</option></term> |
| 765 |
<listitem> |
| 766 |
<para>The kernel number for this device. For example, <literal>sda3</literal> has kernel number |
| 767 |
3.</para> |
| 768 |
</listitem> |
| 769 |
</varlistentry> |
| 770 |
|
| 771 |
<varlistentry> |
| 772 |
<term><option>$devpath</option>, <option>%p</option></term> |
| 773 |
<listitem> |
| 774 |
<para>The devpath of the device.</para> |
| 775 |
</listitem> |
| 776 |
</varlistentry> |
| 777 |
|
| 778 |
<varlistentry> |
| 779 |
<term><option>$id</option>, <option>%b</option></term> |
| 780 |
<listitem> |
| 781 |
<para>The name of the device matched while searching the devpath |
| 782 |
upwards for <option>SUBSYSTEMS</option>, <option>KERNELS</option>, |
| 783 |
<option>DRIVERS</option>, and <option>ATTRS</option>. |
| 784 |
</para> |
| 785 |
</listitem> |
| 786 |
</varlistentry> |
| 787 |
|
| 788 |
<varlistentry> |
| 789 |
<term><option>$driver</option></term> |
| 790 |
<listitem> |
| 791 |
<para>The driver name of the device matched while searching the |
| 792 |
devpath upwards for <option>SUBSYSTEMS</option>, |
| 793 |
<option>KERNELS</option>, <option>DRIVERS</option>, and |
| 794 |
<option>ATTRS</option>. |
| 795 |
</para> |
| 796 |
</listitem> |
| 797 |
</varlistentry> |
| 798 |
|
| 799 |
<varlistentry> |
| 800 |
<term><option>$attr{<replaceable>file</replaceable>}</option>, <option>%s{<replaceable>file</replaceable>}</option></term> |
| 801 |
<listitem> |
| 802 |
<para>The value of a sysfs attribute found at the device where |
| 803 |
all keys of the rule have matched. If the matching device does not |
| 804 |
have such an attribute, and a previous <option>KERNELS</option>, |
| 805 |
<option>SUBSYSTEMS</option>, <option>DRIVERS</option>, or |
| 806 |
<option>ATTRS</option> test selected a parent device, then the |
| 807 |
attribute from that parent device is used. |
| 808 |
</para> |
| 809 |
<para>If the attribute is a symlink, the last element of the |
| 810 |
symlink target is returned as the value. |
| 811 |
</para> |
| 812 |
</listitem> |
| 813 |
</varlistentry> |
| 814 |
|
| 815 |
<varlistentry> |
| 816 |
<term><option>$env{<replaceable>key</replaceable>}</option>, <option>%E{<replaceable>key</replaceable>}</option></term> |
| 817 |
<listitem> |
| 818 |
<para>A device property value.</para> |
| 819 |
</listitem> |
| 820 |
</varlistentry> |
| 821 |
|
| 822 |
<varlistentry> |
| 823 |
<term><option>$major</option>, <option>%M</option></term> |
| 824 |
<listitem> |
| 825 |
<para>The kernel major number for the device.</para> |
| 826 |
</listitem> |
| 827 |
</varlistentry> |
| 828 |
|
| 829 |
<varlistentry> |
| 830 |
<term><option>$minor</option>, <option>%m</option></term> |
| 831 |
<listitem> |
| 832 |
<para>The kernel minor number for the device.</para> |
| 833 |
</listitem> |
| 834 |
</varlistentry> |
| 835 |
|
| 836 |
<varlistentry> |
| 837 |
<term><option>$result</option>, <option>%c</option></term> |
| 838 |
<listitem> |
| 839 |
<para>The string returned by the external program requested with |
| 840 |
<varname>PROGRAM</varname>. |
| 841 |
A single part of the string, separated by a space character, may be selected |
| 842 |
by specifying the part number as an attribute: <literal>%c{N}</literal>. |
| 843 |
If the number is followed by the <literal>+</literal> character, this part plus all remaining parts |
| 844 |
of the result string are substituted: <literal>%c{N+}</literal>.</para> |
| 845 |
</listitem> |
| 846 |
</varlistentry> |
| 847 |
|
| 848 |
<varlistentry> |
| 849 |
<term><option>$parent</option>, <option>%P</option></term> |
| 850 |
<listitem> |
| 851 |
<para>The node name of the parent device.</para> |
| 852 |
</listitem> |
| 853 |
</varlistentry> |
| 854 |
|
| 855 |
<varlistentry> |
| 856 |
<term><option>$name</option></term> |
| 857 |
<listitem> |
| 858 |
<para>The current name of the device. If not changed by a rule, it is the |
| 859 |
name of the kernel device.</para> |
| 860 |
</listitem> |
| 861 |
</varlistentry> |
| 862 |
|
| 863 |
<varlistentry> |
| 864 |
<term><option>$links</option></term> |
| 865 |
<listitem> |
| 866 |
<para>A space-separated list of the current symlinks. The value is |
| 867 |
only set during a remove event or if an earlier rule assigned a value.</para> |
| 868 |
</listitem> |
| 869 |
</varlistentry> |
| 870 |
|
| 871 |
<varlistentry> |
| 872 |
<term><option>$root</option>, <option>%r</option></term> |
| 873 |
<listitem> |
| 874 |
<para>The udev_root value.</para> |
| 875 |
</listitem> |
| 876 |
</varlistentry> |
| 877 |
|
| 878 |
<varlistentry> |
| 879 |
<term><option>$sys</option>, <option>%S</option></term> |
| 880 |
<listitem> |
| 881 |
<para>The sysfs mount point.</para> |
| 882 |
</listitem> |
| 883 |
</varlistentry> |
| 884 |
|
| 885 |
<varlistentry> |
| 886 |
<term><option>$devnode</option>, <option>%N</option></term> |
| 887 |
<listitem> |
| 888 |
<para>The name of the device node.</para> |
| 889 |
</listitem> |
| 890 |
</varlistentry> |
| 891 |
|
| 892 |
<varlistentry> |
| 893 |
<term><option>%%</option></term> |
| 894 |
<listitem> |
| 895 |
<para>The <literal>%</literal> character itself.</para> |
| 896 |
</listitem> |
| 897 |
</varlistentry> |
| 898 |
|
| 899 |
<varlistentry> |
| 900 |
<term><option>$$</option></term> |
| 901 |
<listitem> |
| 902 |
<para>The <literal>$</literal> character itself.</para> |
| 903 |
</listitem> |
| 904 |
</varlistentry> |
| 905 |
</variablelist> |
| 906 |
</refsect2> |
| 907 |
</refsect1> |
| 908 |
|
| 909 |
<refsect1> |
| 910 |
<title>See Also</title> |
| 911 |
<para><simplelist type="inline"> |
| 912 |
<member><citerefentry> |
| 913 |
<refentrytitle>systemd-udevd.service</refentrytitle><manvolnum>8</manvolnum> |
| 914 |
</citerefentry></member> |
| 915 |
<member><citerefentry> |
| 916 |
<refentrytitle>udevadm</refentrytitle><manvolnum>8</manvolnum> |
| 917 |
</citerefentry></member> |
| 918 |
<member><citerefentry> |
| 919 |
<refentrytitle>systemd.link</refentrytitle><manvolnum>5</manvolnum> |
| 920 |
</citerefentry></member> |
| 921 |
</simplelist></para> |
| 922 |
</refsect1> |
| 923 |
</refentry> |