|
213 | 213 | socket-based activation which make dependencies implicit, |
214 | 214 | resulting in a both simpler and more flexible system.</para> |
215 | 215 |
|
216 | | - <para>Some unit names reflect paths existing in the file system |
217 | | - namespace. Example: a device unit |
218 | | - <filename>dev-sda.device</filename> refers to a device with the |
219 | | - device node <filename noindex='true'>/dev/sda</filename> in the |
220 | | - file system namespace. If this applies, a special way to escape |
221 | | - the path name is used, so that the result is usable as part of a |
222 | | - filename. Basically, given a path, "/" is replaced by "-", and all |
223 | | - other characters which are not ASCII alphanumerics are replaced by |
224 | | - C-style "\x2d" escapes (except that "_" is never replaced and "." |
225 | | - is only replaced when it would be the first character in the |
226 | | - escaped path). The root directory "/" is encoded as single dash, |
227 | | - while otherwise the initial and ending "/" are removed from all |
228 | | - paths during transformation. This escaping is reversible. Properly |
229 | | - escaped paths can be generated using the |
230 | | - <citerefentry><refentrytitle>systemd-escape</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
231 | | - command.</para> |
232 | 216 |
|
233 | 217 | <para>Optionally, units may be instantiated from a |
234 | 218 | template file at runtime. This allows creation of |
|
265 | 249 |
|
266 | 250 | </refsect1> |
267 | 251 |
|
| 252 | + <refsect1> |
| 253 | + <title>String Escaping for Inclusion in Unit Names</title> |
| 254 | + |
| 255 | + <para>Sometimes it is useful to convert arbitrary strings into unit names. To facilitate this, a method of string |
| 256 | + escaping is used, in order to map strings containing arbitrary byte values (except NUL) into valid unit names and |
| 257 | + their restricted character set. A common special case are unit names that reflect paths to objects in the file |
| 258 | + system hierarchy. Example: a device unit <filename>dev-sda.device</filename> refers to a device with the device |
| 259 | + node <filename noindex='true'>/dev/sda</filename> in the file system.</para> |
| 260 | + |
| 261 | + <para>The escaping algorithm operates as follows: given a string, any <literal>/</literal> character is replaced by |
| 262 | + <literal>-</literal>, and all other characters which are not ASCII alphanumerics or <literal>_</literal> are |
| 263 | + replaced by C-style <literal>\x2d</literal> escapes. In addition, <literal>.</literal> is replaced with such a |
| 264 | + C-style escape when it would appear as the first character in the escaped string.</para> |
| 265 | + |
| 266 | + <para>When the input qualifies as absolute file system path, this algorithm is extended slightly: the path to the |
| 267 | + root directory <literal>/</literal> is encoded as single dash <literal>-</literal>. In addition, any leading, |
| 268 | + trailing or duplicate <literal>/</literal> characters are removed from the string before transformation. Example: |
| 269 | + <filename>/foo//bar/baz/</filename> becomes <literal>foo-bar-baz</literal>.</para> |
| 270 | + |
| 271 | + <para>This escaping is fully reversible, as long as it is known whether the escaped string was a path (the |
| 272 | + unescaping results are different for paths and non-path strings). The |
| 273 | + <citerefentry><refentrytitle>systemd-escape</refentrytitle><manvolnum>1</manvolnum></citerefentry> command may be |
| 274 | + used to apply and reverse escaping on arbitrary strings. Use <command>systemd-escape --path</command> to escape |
| 275 | + path strings, and <command>systemd-escape</command> without <option>--path</option> otherwise.</para> |
| 276 | + </refsect1> |
| 277 | + |
268 | 278 | <refsect1> |
269 | 279 | <title>Implicit Dependencies</title> |
270 | 280 |
|
|
1241 | 1251 | <row> |
1242 | 1252 | <entry><literal>%N</literal></entry> |
1243 | 1253 | <entry>Unescaped full unit name</entry> |
1244 | | - <entry>Same as <literal>%n</literal>, but with escaping undone</entry> |
| 1254 | + <entry>Same as <literal>%n</literal>, but with escaping undone. This undoes the escaping used when generating unit names from arbitrary strings (see above). </entry> |
1245 | 1255 | </row> |
1246 | 1256 | <row> |
1247 | 1257 | <entry><literal>%p</literal></entry> |
|
1266 | 1276 | <row> |
1267 | 1277 | <entry><literal>%f</literal></entry> |
1268 | 1278 | <entry>Unescaped filename</entry> |
1269 | | - <entry>This is either the unescaped instance name (if applicable) with <filename>/</filename> prepended (if applicable), or the unescaped prefix name prepended with <filename>/</filename>.</entry> |
| 1279 | + <entry>This is either the unescaped instance name (if applicable) with <filename>/</filename> prepended (if applicable), or the unescaped prefix name prepended with <filename>/</filename>. This implements unescaping according to the rules for escaping absolute file system paths discussed above.</entry> |
1270 | 1280 | </row> |
1271 | 1281 | <row> |
1272 | 1282 | <entry><literal>%t</literal></entry> |
|
0 commit comments