Closed acheronfail closed 1 year ago
The I
instead of the G
is probably the length of the message, with two quotes the messages becomes two bytes longer and I
is two letters behind G
in the alphabet. See if eavesdrop=true
makes any difference.
Also feel free to revive https://github.com/diwic/dbus-rs/pull/392
As a side note, the spec thinks the true and false should be in quotes: https://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-routing-match-rules
The I instead of the G is probably the length of the message, with two quotes the messages becomes two bytes longer and I is two letters behind G in the alphabet. See if eavesdrop=true makes any difference.
Ah, you're right! Can't believe I missed that.
As a side note, the spec thinks the true and false should be in quotes: dbus.freedesktop.org/doc/dbus-specification.html#message-bus-routing-match-rules
Ah sweet, so we're doing the right thing here.
Also feel free to revive https://github.com/diwic/dbus-rs/pull/392
Alright, so I looked into that, and it looks like the previous thoughts were that dbus-monitor
just sets up a match with an empty string if BecomeMonitor fails but I don't think that's actually the case with what I'm doing.
As I understand dbus-monitor.c
, it does this:
if (BecomeMonitor succeeds) {
// success
}
else if (We have a filter) {
// try: `eavesdrop=true' + filter
// if that fails, try: filter
// if that fails, error
} else {
// try `eavesdrop=true` by itself
// if that fails, try: "" (empty string
// if that fails, error
}
Since my "filter" is type='signal',interface='org.freedesktop.NetworkManager'
I'm hitting that middle block in the if/else
chain, and that succeeds in dbus-monitor
, but it fails as described above when I try to do the same with this crate. :thinking:
Ah, actually I got it working!
falling back to eavesdrop: Rejected send message, 1 matched rules; type="method_call", sender=":1.81" (uid=1000 pid=12764 comm="target/debug/dbus-system-monitor") interface="org.freedesktop.DBus.Monitoring" member="BecomeMonitor" error name="(unset)" requested_reply="0" destination="org.freedesktop.DBus" (bus)
Got message: Message { Type: Signal, Path: "/org/freedesktop/NetworkManager", Interface: "org.freedesktop.NetworkManager", Member: "StateChanged", Sender: ":1.5", Serial: 845, Args: [30] }
Got message: Message { Type: Signal, Path: "/org/freedesktop/NetworkManager", Interface: "org.freedesktop.NetworkManager", Member: "StateChanged", Sender: ":1.5", Serial: 876, Args: [20] }
Got message: Message { Type: Signal, Path: "/org/freedesktop/NetworkManager", Interface: "org.freedesktop.NetworkManager", Member: "StateChanged", Sender: ":1.5", Serial: 920, Args: [40] }
Got message: Message { Type: Signal, Path: "/org/freedesktop/NetworkManager", Interface: "org.freedesktop.NetworkManager", Member: "StateChanged", Sender: ":1.5", Serial: 968, Args: [60] }
So, my example was doing this:
But, as I said above, dbus-monitor
does this:
If I don't set eavesdrop in my example above, then it works the same as dbus-monitor
.
I think the most confusing part was dbus-monitor
's output, since it appears to be working using eavedrop, but in reality eavesdrop also failed, and it's just using regular matching.
Thanks for all your help on this! I'm going to close this issue since I've figured out how it works.
I'm trying to monitor the system bus and am having some issues.
Using the monitor example as a base, I've created a repository here: https://github.com/acheronfail/dbus-system-monitor/ (just adds a type and interface to the match rule).
The problem
I want to be able to do what
dbus-monitor
does when it can'tBecomeMonitor
:As you can see, its
BecomeMonitor
request fails if the user is notroot
, and then it "falls back" to eavesdropping. The monitor example also does this, but if I try to run it, it fails:So, the monitor example also falls back to eavesdrop=true, but it fails when doing so.
Investigations
I've been using
strace
to compare, and I've found that this crate sends a very slightly different message to dbus, observe:Specifically, compare the second item in the
sendmsg
calls:Observations
There are two differences:
eavesdrop=true
vseavesdrop='true'
:dbus-monitor
doesn't quotetrue
. I'm not convinced this is the issueG
indbus-monitor
, but indbus-rs
it'sI
: to me, this seems like a likely case?I've been trying to get
dbus-rs
to send a message withG
instead ofI
, but I'm getting lost in all theimpl
s and macros insidedbus-rs
:sweat_smile:Do you have any idea what could be going on here? Or anything to point me in the right direction?