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.
The commands halevt and halevt-mount options and synopsis are given in the halevt and halevt-mount pages.
Some examples are provided in the Halevt distribution.
The configuration file used can be set on the command line using -c file. Otherwise halevt will use all the files ending in ‘.xml’ located in the following directories, in that order:
When in reporting mode, turned on by the -i option, no configuration file is used, halevt reports all the HAL events.
Halevt configuration is in XML (described in-depth at http://www.w3.org/XML/). A configuration file should begin with:
<?xml version="1.0" encoding="UTF-8"?> <halevt:Configuration version="0.1" xmlns:halevt="http://www.environnement.ens.fr/perso/dumas/halevt.html">
and end with
Comments are within ‘<!--’ and ‘-->’.
Basically, there are nested elements marked by ‘<...>’, either with a start tag and an end tag with a slash marking the end tag ‘</...>’, like the ‘halevt:Device’ element:
<halevt:Device ...> .... </halevt:Device>
or standalone, like the ‘halevt:Insertion’ element, ending with a ‘/>’:
In the element there may be attributes, with a name followed by an equal sign followed by a quoted string for the corresponding value. Here is an example of a ‘match’ attribute for the ‘halevt:Device’ element:
<halevt:Device match="hal.block.device & hal.block.is_volume"> ..... </halevt:Device>
Since they have special meanings, a literal ‘"’ should be escaped as ‘"’, ‘&’ should be escaped as ‘&’, ‘<’ as ‘<’ and ‘>’ as ‘>’.
For example the
exec attribute here:
<halevt:Device match="hal.block.device & hal.block.is_volume"> <halevt:Insertion exec="echo "$hal.udi$" > file"/> </halevt:Device>
echo "$hal.udi$" > file
The configuration of halevt allows to select device such that a command is run upon an hal event. The device selection is handled by the ‘halevt:Device’ element, it encloses an action element, among
halevt:Actionelement is nested within the
halevt:Propertyelement to select an action based on the property value.
halevt:Device has a
match 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 ‘&’ for and, ‘|’ for or and ‘!’ for the negation and
parenthesis for grouping.
A hal property that should exist is selected by prepending ‘hal.’ to the property, like ‘hal.block.device’. A property value match is specified by the property name with ‘hal.’ prepended followed by an equal sign followed by the value. For example, the following is true if the device property ‘block.is_volume’ has ‘true’ as a value:
hal.block.is_volume = true
So, for example, the following selects devices with existing ‘block.device’ property, and a property ‘block.is_volume’ matching the value ‘true’:
<halevt:Device match="hal.block.device & hal.block.is_volume = true> ... </halevt:Device>
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 ‘hal.’ between the UDI device property and the property to check. For example the following checks that the device specified by the ‘block.storage_device’ property has the ‘storage.hotpluggable’ property set to ‘true’:
hal.block.storage_device.hal.storage.hotpluggable = true
If the property to check is also an UDI, the UDI can be considered to be another device and so on and so forth.
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
exec attribute. It will be in an element
corresponding with the HAL event. The
exec attribute simply
holds the command to be run, and it is possible to substitute a
hal property value, by enclosing in ‘$..$’ the property name
with hal prepended. Also
$hal.udi$ is replaced by the device
UDI. For example in:
exec="halevt-mount -u $hal.udi$ -d $hal.block.device$ -o sync -m 002"
$hal.udi$ is replaced by the device UDI and
is replaced by the ‘block.device’ property value for the device.
An action is performed for a selected device, therefore action element
should appear within
The following action possibility exist, each associated with a HAL
execattribute, 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.
<halevt:Device match="hal.block.device"> <halevt:OnInit exec="halevt-mount -u $hal.udi$"/> </halevt:Device>
execattribute. This does exactly the same than above, but on device insertion:
<halevt:Device match="hal.block.device"> <halevt:Insertion exec="halevt-mount -u $hal.udi$"/> </halevt:Device>
execattribute. For example:
<halevt:Device match="hal.block.device"> <halevt:Removal exec="halevt-umount -d $hal.block.device$"/> </halevt:Device>
nameattribute allows to specify the condition, while the
execattribute specifies the action. An optional
valueattribute may also be used to match only for a given condition detail value. For example:
<halevt:Device match="hal.info.udi = /org/freedesktop/Hal/devices/acpi_PWRF"> <halevt:Condition name="ButtonPressed" exec="sudo /sbin/shutdown"/> </halevt:Device>
With a value:
<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>
nameattribute of the
halevt:Actionelement is nested within the
halevt:Propertyelement to select an action based on the property value. In the
valueattribute allows to specify which value for the property should lead to the action to be taken, and the
execattribute specifies the command to be run. ‘*’ as an
valuewill match any value. For example:
<halevt:Device match="hal.block.device & hal.block.is_volume = true"> <halevt:Property name="hal.volume.is_mounted"> <halevt:Action value="true" exec="halevt-mount -s"/> </halevt:Property> </halevt:Device>
In that example, the property that changes is ‘volume.is_mounted’, and the action is executed when the value of ‘volume.is_mounted’ becomes ‘true’.
The hal properties are very important in halevt, but cannot necessarily be found easily. Here are some tricks.
To discover what changes when a device is inserted, one can use lshal -m. 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.
Also, one can use lshal to list the devices with their
properties. The properties can then be used in
prepended by ‘hal.’, and also in
exec, also prepended by ‘hal’
and enclosed in ‘$’, like:
exec="halevt-mount -d $hal.block.device$"
Reference to other UDI are recognizable because they begin with
For example, one can have:
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)
The properties of those devices can be used as explained in Device selection syntax.