dnscrypto-proxy: Update to release 1.3.0
[tomato.git] / release / src / router / hotplug2 / docs / hotplug2.rules.doc
blob6880861b1386d9b9624ee714b636868081ad7b0a
1  INTRO
2  -----
4 This document describes the format of /etc/hotplug2.rules file.
6 The general syntax is:
8 <key> <condition type> <value> [, <key> <condition type> <value> [,...]] {
9         action [parameter]
10         [action [parameter]]
11         [... [...]]
14 Comments are allowed, they are prefixed with '#', treating the whole rest of
15 the line as comment. Please note that comments in place of action parameters
16 are not supported.
18 The <key> is one of the environmental variables that have been obtained by
19 the uevent netlink. 
21  COMMON KEYS
22  -----------
24 The most common keys available are: 
25  * ACTION
27  * SUBSYSTEM
29  * DEVPATH
31  * MODALIAS
33  * MAJOR
35  * MINOR
37 These values are also substituted by "%variable%", eg. "%MODALIAS". There is
38 a variable not sent by kernel, but exported nonetheless: DEVICENAME. This
39 variable is set if DEVPATH is set, and is result of basename(DEVPATH).
42  CONDITION TYPES
43  ---------------
45 Conditiom types specify the realtionship between <key> and <value>.
46 Available condition types are:
47  * ==
48         Values are equal, case sensitive
50  * !=
51         Values are not equal, case sensitive
53  * ~~
54         The content of <key> matches regex pattern in <value>
56  * !~
57         The content of <key> does not match regex pattern in <value> 
59  * is
60         This is a special condition type. Valid values for it are 'set' and
61         'unset', specifying the key has any value at all or not. Any other
62         value implies the condition fails.
65   ACTIONS
66   -------
68  * run <...>
69         Execute an application using system();, takes one parameter. Note
70         that the application has set all environmental variables read by 
71         uevent netlink.
73  * break
74         Break the processing of the current block of actions.
76  * break_if_failed
77         Break if return value from the last action was non-zero.
79  * next
80         Continue to the next event, do not process any more rules for the
81         current one.
83  * next_if_failed
84         Continue to the next event if return value from the last action was 
85         non-zero.
87  * exec <application [parameter [parameter [...]]]> ;
88         Execute an application. Takes variable number of parameters, but the
89         last parameter must be terminated with semicolon. Again, all
90         variables are set as environmental.
91         
92         If you need to escape the ';', use '\\;'. Only applies for actions
93         with variable number of parameters.
94         
95  * makedev <path> <mode>
96         Create a device with given mode. Mode is interpreted as octal.
97         
98         Major, minor and devpath must be set for makedev to be able to work.
99         Tests for these variables are also performed internally in makedev
100         function.
102  * symlink <target> <linkname>
103         Create a symbolic link (symlink, also known as soft link) pointing
104         at target with name linkname.
105         
106  * chown <path> <owner name>
107         Change owner of path to owner name.
108         
109  * chgrp <path> <group name>
110         Change group of path to group name.
111         
112  * chmod <path> <mode>
113         Change mode of path to given mode. Mode is interpreted as octal.
115  * setenv <key> <value>
116         Sets environmental variable key to the given value. If an env var
117         of the given name already exists, it gets overwritten.
119  * printdebug
120         Prints all variables read from kernel.
122  FLAGS
123  -----
125 Flags are, syntactically, just like actions; their semantical value is different however.
126 Instead of doing something, they instead change the general behavior of the processing
127 of the given rule.
129 Note that for flags to work, you also have to invoke it with --override.
131 Currently, only one flag is implemented:
133  * nothrottle
134         Forcibly overrides hotplug2 throttling mechanism. If _all_ rules that match
135         the given kernel event have 'nothrottle' set, hotplug2 will not wait for
136         children count to get under max-children limit. That allows to throttle
137         eg. helper application execution or modprobes, but yet keep node devices
138         fast.
139         
140  ESCAPING
141  --------
143 There are several items you may like to escape:
144  * variable substitution
145         You can escape variable substituion by "%\\variable%\\".
146         
147  * action block terminator '}'
148         Similarly, to escape action block terminator, use '\\}'
150  * variable parameter terminator ';' (semicolon)
151         Likewise, you can use '\\;' to escape variable parameter terminator.
152         Note that this only works for actions that take variable number of
153         paramteres, such as 'exec'.
155  SAMPLE CONFIG
156  -------------
158 Below is a sample hotplug2.rules file. It loads modules to all available
159 devices quietly and creates device nodes for block devices. Note that this
160 sample is not very viable for real life usage.
161 ---------------------------------------------------------------------------------
162 MODALIAS is set {
163         exec modprobe -q %MODALIAS% ;
166 SUBSYSTEM == block, DEVPATH is set, MAJOR is set, MINOR is set {
167         makedev /dev/%DEVICENAME% 0644
171 Please find also the more complex set of rules, dedicated to handling most
172 common needs.
173 ---------------------------------------------------------------------------------
174 #For debugging
175 #ACTION is set {
176 #       printdebug
179 # Load modules (what old hotplug did)
180 MODALIAS is set {
181         exec modprobe -q %MODALIAS% ;
184 # Create device nodes
185 DEVPATH is set, MAJOR is set, MINOR is set {
186         makedev /dev/%DEVICENAME% 0644
189 # Mount a USB flashdisk
190 ACTION == add, PHYSDEVPATH ~~ "/usb[0-9]*/", DEVICENAME ~~ "^sd[a-z][0-9]+$", DEVPATH is set, MAJOR is set, MINOR is set {
191         makedev /dev/%DEVICENAME% 0644
192         exec mount /dev/%DEVICENAME% /mnt/%DEVICENAME%
195 # Unmount a USB flashdisk
196 ACTION == remove, PHYSDEVPATH ~~ "/usb[0-9]*/", DEVICENAME ~~ "^sd[a-z][0-9]+$", MAJOR is set, MINOR is set {
197         exec umount /mnt/%DEVICENAME%