commandline tool to trigger actions on dbus-signal

Robin Gareus robin at gareus.org
Wed Feb 23 07:33:07 PST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02/22/2011 09:24 AM, Mikkel Kamstrup Erlandsen wrote:
> On Mon, 2011-02-21 at 22:27 +0100, Robin Gareus wrote:
>> Hi *,
>>
>> I'm searching a simple commandline-tool (akin to dbus-monitor,
>> dbus-send) that invokes a shell-command upon receiving a given dbus signal.
>>
>> I'm new around here. If there's a better place to get answers to this
>> question, please advice.
>>
>> I'm wondering if it's worth to pursue
>>  git://rg42.org/dbustriggerd
>>
>> I'm interested in alternatives: What do you do to trigger shell-commands
>> via dbus messages? Can it be done [easily] without resorting to
>> dbus-python or other binding languages?
> 
> dbus-monitor can do this for you already. You can give dbus-monitor an
> arbitrary match rule string[1], so an example match on a signal:
> 
>   dbus-monitor
> "type='signal',interface='com.example.SuperService',member='DuperSignal'"
> 
> Then pipe that into some process that reads from stdin, does something,
> and then exits once it reads anything off stdin.

Thanks for the suggestion, I tried that alike:
  dbus-monitor | awk '/^signal/{system("echo " $0);}


dbus-monitor's '--profile' is easy to parse, but does not include
arguments.
Parsing '--monitor' mode multi-line output can become tricky (eg. a
string argument could include "blah\nsignal sender" The parser will need
to check quotes over multiple lines (which is not trivial on the
commandline). A minor annoyance is to ignore the NameAcquired signal.
All in all: using `dbus-monitor` to trigger commands is rather a project
in itself and not suitable to be used as instrumentation-tool to trigger
actions for testing.

I suppose the most pragmatic way would have been to use a few python lines..

> I've never actually tried this, but I'm pretty sure it should work. The
> crucial point is whether dbus-monitor exits if stdout is closed. And it
> does - I just checked dbus-monitor | head -1 :-)
>
> Cheers,
> Mikkel
>

not here with dbus-1.2.24-4 from debian. I guess I should upgrade :)
But it flushes the output-buffer, so `read` gets it with very little delay.

Anyway, i've brought http://rg42.org/oss/dbustriggerd/ up to scratch.
It's a small tool based on dbus-monitor.c to invoke shell commands. If
you're interested it'd be trivial to include this upstream in tools.

ciao,
robin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk1lKLMACgkQeVUk8U+VK0IWZQCeKt49FhBTYtltzelq6j67LKJZ
Fe8AoIdlf82FHi5ur1PYmgR5hmPwHqEf
=lcFu
-----END PGP SIGNATURE-----


More information about the dbus mailing list