2014-10-07 23 views
3

我试图让dbus-send --address工作在地址127.0.0.1端口10010为自定义方法(com.example.Test.TestMethod)我写了我自己。它本身并不是一件有用的事情,但我试图完成更多的事情,这是一个测试步骤。使用dbus发送地址127.0.0.1为自定义方法


首先,我已经说服自己我的测试方法的工作原理应该如此。在本地使用系统总线成功为我的方法:

$ dbus-send --system --print-reply --type=method_call --dest=com.example.Test /com/example/Test com.example.Test.TestMethod string:foo 
method return sender=:1.0 -> dest=:1.17 reply_serial=2 
    string "returning foo" 

其次,使用--address失败(我不明白为什么失败):

$ dbus-send --address=tcp:host=127.0.0.1,port=10010 --print-reply --type=method_call --dest=com.example.Test /com/example/Test com.example.Test.TestMethod string:foo 
Error org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken. 

dbus-monitor表示绝对没有:

$ DBUS_VERBOSE=1 dbus-monitor --system 
(nothing) 

三,使用--addressorg.freedesktop.DBus.Hello成功。我不知道为什么会成功,而我的方法失败:

$ dbus-send --address=tcp:host=127.0.0.1,port=10010 --print-reply --type=method_call --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.Hello 
method return sender=org.freedesktop.DBus -> dest=:1.15 reply_serial=1 
    string ":1.15" 

我已经做了一些修改配置文件/etc/dbus-1/system.conf

<auth>ANONYMOUS</auth> 
    <allow_anonymous/> 

<listen>tcp:host=127.0.0.1,port=10010</listen> 

    <allow send_destination="com.example.Test"/> 
    <allow own="com.example.Test"/> 

对于调试,我我在dbus-send上使用了DBUS_VERBOSE=1,但在输出中看不到任何用处。失败案例和成功案例都不同的最小输出:

成功案例(org.freedesktop.DBus.Hello):

[dbus/dbus-transport-socket.c(879):do_reading] read 89 bytes 
[dbus/dbus-marshal-header.c(745):_dbus_header_have_message_untrusted] have 89 bytes, need body 9 + header 80 = 89 
[dbus/dbus-marshal-validate.c(723):_dbus_validate_body_with_reason] validating body from pos 0 len 89 sig 'yyyyuua(yv)' 

失败的情况下(com.example.Test.TestMethod):

[dbus/dbus-transport-socket.c(873):do_reading] Disconnected from remote app 
[dbus/dbus-transport.c(502):_dbus_transport_disconnect] start 
[dbus/dbus-transport-socket.c(1017):socket_disconnect] 
[dbus/dbus-transport-socket.c(76):free_watches] start 
[dbus/dbus-watch.c(628):dbus_watch_set_data] Setting watch fd -1 data to data = (nil) function = (nil) from data = (nil) function = (nil) 
[dbus/dbus-watch.c(628):dbus_watch_set_data] Setting watch fd -1 data to data = (nil) function = (nil) from data = (nil) function = (nil) 
[dbus/dbus-transport-socket.c(98):free_watches] end 
[dbus/dbus-transport.c(513):_dbus_transport_disconnect] end 

,我也开始了调试模式dbus-daemonDBUS_VERBOSE=1,但我无法找到任何地方的输出。它不在syslog中。有可能我没有调试版本,但我发现不太可能,因为dbus-senddbus-monitor明显是调试版本。


我已经在会话总线上尝试了相同的实验,结果相同。


版本信息:

$ dbus-daemon --version 
D-Bus Message Bus Daemon 1.6.8 

$ cat /etc/debian_version 
7.6 

我的最终目标是使用d-BUS进行计算机之间传递消息。获得dbus-send --address为当地案件工作只是我的第一步。


更新10月。2014年第16期:我能够得到这个工作。该解决方案与直觉相反。

有两个要求。

您必须使用总线使用系统进行通信。 您必须设置SESSION总线地址环境变量。

$ DBUS_SESSION_BUS_ADDRESS=tcp:host=192.168.56.101,port=10010 dbus-send --print-reply --type=method_call --dest=com.example.Test /com/example/Test com.example.Test.TestMethod string:foo 

回答

0

我想这是因为DBUS守护询问local secret和你的客户不知道如何读它。你可以尝试用wireshirk转储整个握手吗? (或者,您可以使用我的dbus-dissect脚本,但它可能需要一些源代码调整)

相关问题