<html lang="en"> <head> <title>Halevt configuation</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="Halevt configuation"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="top" href="#Top"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <!-- Copyright (C) 2008, 2009 Patrice Dumas Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.--> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="Top"></a> <p><hr> Next: <a rel="next" accesskey="n" href="#Configuration-file-locations">Configuration file locations</a>, Up: <a rel="up" accesskey="u" href="#dir">(dir)</a> </div> <h2 class="unnumbered">Halevt configuration</h2> <h3 class="heading">License of this document</h3> <p class="noindent">Copyright (C) 2008, 2009 Patrice Dumas<br> <p>Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. <p>Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. <h3 class="heading">Other sources of information</h3> <p>The commands <samp><span class="command">halevt</span></samp> and <samp><span class="command">halevt-mount</span></samp> options and synopsis are given in the <a href="halevt.1.html">halevt</a> and <a href="halevt-mount.1.html">halevt-mount</a> pages. <p>Some examples are provided in the Halevt distribution. <ul class="menu"> <li><a accesskey="1" href="#Configuration-file-locations">Configuration file locations</a> <li><a accesskey="2" href="#Halevt-configuration-syntax">Halevt configuration syntax</a> <li><a accesskey="3" href="#Discovering-hal-properties">Discovering hal properties</a> </ul> <div class="node"> <a name="Configuration-file-locations"></a> <p><hr> Next: <a rel="next" accesskey="n" href="#Halevt-configuration-syntax">Halevt configuration syntax</a>, Previous: <a rel="previous" accesskey="p" href="#Top">Top</a>, Up: <a rel="up" accesskey="u" href="#Top">Top</a> </div> <h2 class="chapter">1 Configuration file locations</h2> <p>The configuration file used can be set on the command line using <samp><span class="option">-c </span><var>file</var></samp>. Otherwise <samp><span class="command">halevt</span></samp> will use all the files ending in ‘<samp><span class="samp">.xml</span></samp>’ located in the following directories, in that order: <ol type=1 start=1> <li><samp><span class="file">$HOME/.halevt</span></samp> <li><samp><span class="file">@sysconfdir@/halevt</span></samp> <li><samp><span class="file">@datadir@/halevt</span></samp> </ol> with <samp><span class="file">@sysconfdir@</span></samp> and <samp><span class="file">@datadir@</span></samp> being set during the configuration and build of the software. If a file with a given name has already been found, it is ignored in the other directores. <p>When in reporting mode, turned on by the <samp><span class="option">-i</span></samp> option, no configuration file is used, <samp><span class="command">halevt</span></samp> reports all the HAL events. <div class="node"> <a name="Halevt-configuration-syntax"></a> <p><hr> Next: <a rel="next" accesskey="n" href="#Discovering-hal-properties">Discovering hal properties</a>, Previous: <a rel="previous" accesskey="p" href="#Configuration-file-locations">Configuration file locations</a>, Up: <a rel="up" accesskey="u" href="#Top">Top</a> </div> <h2 class="chapter">2 Halevt configuration syntax</h2> <ul class="menu"> <li><a accesskey="1" href="#Basic-syntax-of-halevt-xml-files">Basic syntax of halevt xml files</a> <li><a accesskey="2" href="#Selecting-devices-and-actions-for-hal-events">Selecting devices and actions for hal events</a> </ul> <div class="node"> <a name="Basic-syntax-of-halevt-xml-files"></a> <p><hr> Next: <a rel="next" accesskey="n" href="#Selecting-devices-and-actions-for-hal-events">Selecting devices and actions for hal events</a>, Up: <a rel="up" accesskey="u" href="#Halevt-configuration-syntax">Halevt configuration syntax</a> </div> <h3 class="section">2.1 Basic syntax of halevt xml files</h3> <p>Halevt configuration is in XML (described in-depth at <a href="http://www.w3.org/XML/">http://www.w3.org/XML/</a>). A configuration file should begin with: <pre class="example"> <?xml version="1.0" encoding="UTF-8"?> <halevt:Configuration version="0.1" xmlns:halevt="http://www.environnement.ens.fr/perso/dumas/halevt.html"> </pre> <p>and end with <pre class="example"> </halevt:Configuration> </pre> <p>Comments are within ‘<samp><span class="samp"><!--</span></samp>’ and ‘<samp><span class="samp">--></span></samp>’. <p>Basically, there are nested <dfn>elements</dfn> marked by ‘<samp><span class="samp"><...></span></samp>’, either with a start tag and an end tag with a slash marking the end tag ‘<samp><span class="samp"></...></span></samp>’, like the ‘<samp><span class="samp">halevt:Device</span></samp>’ element: <pre class="example"> <halevt:Device ...> .... </halevt:Device> </pre> <p>or standalone, like the ‘<samp><span class="samp">halevt:Insertion</span></samp>’ element, ending with a ‘<samp><span class="samp">/></span></samp>’: <pre class="example"> <halevt:Insertion ..../> </pre> <p>In the element there may be <dfn>attributes</dfn>, with a name followed by an equal sign followed by a quoted string for the corresponding value. Here is an example of a ‘<samp><span class="samp">match</span></samp>’ attribute for the ‘<samp><span class="samp">halevt:Device</span></samp>’ element: <pre class="example"> <halevt:Device match="hal.block.device &amp; hal.block.is_volume"> ..... </halevt:Device> </pre> <p>Since they have special meanings, a literal ‘<samp><span class="samp">"</span></samp>’ should be escaped as ‘<samp><span class="samp">&quot;</span></samp>’, ‘<samp><span class="samp">&</span></samp>’ should be escaped as ‘<samp><span class="samp">&amp;</span></samp>’, ‘<samp><span class="samp"><</span></samp>’ as ‘<samp><span class="samp">&lt;</span></samp>’ and ‘<samp><span class="samp">></span></samp>’ as ‘<samp><span class="samp">&gt;</span></samp>’. <p>For example the <code>exec</code> attribute here: <pre class="example"> <halevt:Device match="hal.block.device &amp; hal.block.is_volume"> <halevt:Insertion exec="echo &quot;$hal.udi$&quot; &gt; file"/> </halevt:Device> </pre> <p>is <pre class="example"> echo "$hal.udi$" > file </pre> <div class="node"> <a name="Selecting-devices-and-actions-for-hal-events"></a> <p><hr> Previous: <a rel="previous" accesskey="p" href="#Basic-syntax-of-halevt-xml-files">Basic syntax of halevt xml files</a>, Up: <a rel="up" accesskey="u" href="#Halevt-configuration-syntax">Halevt configuration syntax</a> </div> <h3 class="section">2.2 Selecting devices and actions for hal events</h3> <p>The configuration of <samp><span class="command">halevt</span></samp> allows to select device such that a command is run upon an hal event. The device selection is handled by the ‘<samp><span class="samp">halevt:Device</span></samp>’ element, it encloses an action element, among <dl> <dt><code>halevt:OnInit</code><dd>for an action to perform if the device is already there when halevt is started; <br><dt><code>halevt:Insertion</code><dd>for an action ot be performed on device insertion; <br><dt><code>halevt:Removal</code><dd>for an action ot be performed on device removal; <br><dt><code>halevt:Condition</code><dd>for an action to be performed when a condition is emitted by the device; <br><dt><code>halevt:Property</code><dd>for an action to be performed when a property changes. In that case the <code>halevt:Action</code> element is nested within the <code>halevt:Property</code> element to select an action based on the property value. </dl> <ul class="menu"> <li><a accesskey="1" href="#Device-selection-syntax">Device selection syntax</a> <li><a accesskey="2" href="#Specifying-a-command-to-be-executed">Specifying a command to be executed</a> <li><a accesskey="3" href="#Actions">Actions</a> </ul> <div class="node"> <a name="Device-selection-syntax"></a> <p><hr> Next: <a rel="next" accesskey="n" href="#Specifying-a-command-to-be-executed">Specifying a command to be executed</a>, Up: <a rel="up" accesskey="u" href="#Selecting-devices-and-actions-for-hal-events">Selecting devices and actions for hal events</a> </div> <h4 class="subsection">2.2.1 Device selection syntax</h4> <p>A <code>halevt:Device</code> has a <code>match</code> attribute, to select the device. The device match is done by selecting hal properties that should exist or properties matching a value. These items can be combined in boolean expressions, with ‘<samp><span class="samp">&</span></samp>’ for and, ‘<samp><span class="samp">|</span></samp>’ for or and ‘<samp><span class="samp">!</span></samp>’ for the negation and parenthesis for grouping. <p>A hal property that should exist is selected by prepending ‘<samp><span class="samp">hal.</span></samp>’ to the property, like ‘<samp><span class="samp">hal.block.device</span></samp>’. A property value match is specified by the property name with ‘<samp><span class="samp">hal.</span></samp>’ prepended followed by an equal sign followed by the value. For example, the following is true if the device property ‘<samp><span class="samp">block.is_volume</span></samp>’ has ‘<samp><span class="samp">true</span></samp>’ as a value: <pre class="example"> hal.block.is_volume = true </pre> <p>So, for example, the following selects devices with existing ‘<samp><span class="samp">block.device</span></samp>’ property, and a property ‘<samp><span class="samp">block.is_volume</span></samp>’ matching the value ‘<samp><span class="samp">true</span></samp>’: <pre class="example"> <halevt:Device match="hal.block.device &amp; hal.block.is_volume = true> ... </halevt:Device> </pre> <p>When a property is an UDI which specifies a device, it is possible to check a property of the device specified by this UDI, by inserting ‘<samp><span class="samp">hal.</span></samp>’ between the UDI device property and the property to check. For example the following checks that the device specified by the ‘<samp><span class="samp">block.storage_device</span></samp>’ property has the ‘<samp><span class="samp">storage.hotpluggable</span></samp>’ property set to ‘<samp><span class="samp">true</span></samp>’: <pre class="example"> hal.block.storage_device.hal.storage.hotpluggable = true </pre> <p>If the property to check is also an UDI, the UDI can be considered to be another device and so on and so forth. <div class="node"> <a name="Specifying-a-command-to-be-executed"></a> <p><hr> Next: <a rel="next" accesskey="n" href="#Actions">Actions</a>, Previous: <a rel="previous" accesskey="p" href="#Device-selection-syntax">Device selection syntax</a>, Up: <a rel="up" accesskey="u" href="#Selecting-devices-and-actions-for-hal-events">Selecting devices and actions for hal events</a> </div> <h4 class="subsection">2.2.2 Specifying a command to be executed</h4> <p>Every action leads to a command being executed when an HAL event happens for a selected device. The command to run is specified in an attribute, the <code>exec</code> attribute. It will be in an element corresponding with the HAL event. The <code>exec</code> attribute simply holds the command to be run, and it is possible to substitute a hal property value, by enclosing in ‘<samp><span class="samp">$..$</span></samp>’ the property name with hal prepended. Also <code>$hal.udi$</code> is replaced by the device UDI. For example in: <pre class="example"> exec="halevt-mount -u $hal.udi$ -d $hal.block.device$ -o sync -m 002" </pre> <p><code>$hal.udi$</code> is replaced by the device UDI and <code>$hal.block.device$</code> is replaced by the ‘<samp><span class="samp">block.device</span></samp>’ property value for the device. <div class="node"> <a name="Actions"></a> <p><hr> Previous: <a rel="previous" accesskey="p" href="#Specifying-a-command-to-be-executed">Specifying a command to be executed</a>, Up: <a rel="up" accesskey="u" href="#Selecting-devices-and-actions-for-hal-events">Selecting devices and actions for hal events</a> </div> <h4 class="subsection">2.2.3 Actions</h4> <p>An action is performed for a selected device, therefore action element should appear within <code>halevt:Device</code> elements. The following action possibility exist, each associated with a HAL event: <dl> <dt><code>halevt:OnInit</code><dd>This element is associated with an <code>exec</code> attribute, allowing to specify an action to perform if the device is already known by HAL when halevt is started. For example, the following leads to mounting all the block devices known by HAL by UDI. <pre class="example"> <halevt:Device match="hal.block.device"> <halevt:OnInit exec="halevt-mount -u $hal.udi$"/> </halevt:Device> </pre> <br><dt><code>halevt:Insertion</code><dd>This element corresponds with an action to be performed on device insertion, specified by the <code>exec</code> attribute. This does exactly the same than above, but on device insertion: <pre class="example"> <halevt:Device match="hal.block.device"> <halevt:Insertion exec="halevt-mount -u $hal.udi$"/> </halevt:Device> </pre> <br><dt><code>halevt:Removal</code><dd>This element corresponds with an action to be performed on device removal, specified by a <code>exec</code> attribute. For example: <pre class="example"> <halevt:Device match="hal.block.device"> <halevt:Removal exec="halevt-umount -d $hal.block.device$"/> </halevt:Device> </pre> <br><dt><code>halevt:Condition</code><dd>This element corresponds with an action to be performed when a condition is emitted. The <code>name</code> attribute allows to specify the condition, while the <code>exec</code> attribute specifies the action. An optional <code>value</code> attribute may also be used to match only for a given condition detail value. For example: <pre class="example"> <halevt:Device match="hal.info.udi = /org/freedesktop/Hal/devices/acpi_PWRF"> <halevt:Condition name="ButtonPressed" exec="sudo /sbin/shutdown"/> </halevt:Device> </pre> <p>With a value: <pre class="example"> <halevt:Device match="hal.input.originating_device.hal.info.linux.driver = atkbd"> <halevt:Condition name="ButtonPressed" value="mute" exec="amixer -q set Master toggle"/> </halevt:Device> </pre> <br><dt><code>halevt:Property</code><dd>for an action to be performed when a property changes. The property name is specified in the <code>name</code> attribute of the <code>halevt:Property</code> element. An <code>halevt:Action</code> element is nested within the <code>halevt:Property</code> element to select an action based on the property value. In the <code>halevt:Action</code> element, the <code>value</code> attribute allows to specify which value for the property should lead to the action to be taken, and the <code>exec</code> attribute specifies the command to be run. ‘<samp><span class="samp">*</span></samp>’ as an <code>halevt:Action</code> <code>value</code> will match any value. For example: <pre class="example"> <halevt:Device match="hal.block.device &amp; hal.block.is_volume = true"> <halevt:Property name="hal.volume.is_mounted"> <halevt:Action value="true" exec="halevt-mount -s"/> </halevt:Property> </halevt:Device> </pre> <p>In that example, the property that changes is ‘<samp><span class="samp">volume.is_mounted</span></samp>’, and the action is executed when the value of ‘<samp><span class="samp">volume.is_mounted</span></samp>’ becomes ‘<samp><span class="samp">true</span></samp>’. </dl> <div class="node"> <a name="Discovering-hal-properties"></a> <p><hr> Previous: <a rel="previous" accesskey="p" href="#Halevt-configuration-syntax">Halevt configuration syntax</a>, Up: <a rel="up" accesskey="u" href="#Top">Top</a> </div> <h2 class="chapter">3 Tips and tricks for discovering hal properties</h2> <p>The hal properties are very important in halevt, but cannot necessarily be found easily. Here are some tricks. <p>To discover what changes when a device is inserted, one can use <samp><span class="command">lshal -m</span></samp>. Once started, it will wait for hal events and will print all the changes emitted by the hald daemon, allowing to know which UDI was added and which property changed. <p>Also, one can use <samp><span class="command">lshal</span></samp> to list the devices with their properties. The properties can then be used in <code>match</code> prepended by ‘<samp><span class="samp">hal.</span></samp>’, and also in <code>exec</code>, also prepended by ‘<samp><span class="samp">hal</span></samp>’ and enclosed in ‘<samp><span class="samp">$</span></samp>’, like: <pre class="example"> exec="halevt-mount -d $hal.block.device$" </pre> <p>Reference to other UDI are recognizable because they begin with <pre class="example"> /org/freedesktop/Hal/devices/ </pre> <p>For example, one can have: <pre class="example"> info.parent = '/org/freedesktop/Hal/devices/usb_device_47b_2_noserial_if1' (string) input.originating_device = '/org/freedesktop/Hal/devices/usb_device_47b_2_noserial_if1' (string) </pre> <p>The properties of those devices can be used as explained in <a href="#Device-selection-syntax">Device selection syntax</a>. </body></html>