有没有"D-Bus嗅探器"这样的东西?
我想"嗅探"在D-Bus上传输的所有(或部分)消息.
我正在尝试将D-Bus与我的boost::asio应用程序集成.
D-Bus有一个API,可以枚举一组要监视的Unix文件描述符(主要是套接字,但也可以是FIFO).当那些描述符有东西需要阅读时,我应该通知D-Bus API,这样它就可以读取它们并做到这一点.
目前我这样做:
using boost::asio::posix::stream_descriptor;
void read_handle(stream_descriptor* desc, const boost::system::error_code& ec,
std::size_t bytes_read)
{
if (!ec) {
stream_descriptor::bytes_readable command(true);
descriptor->io_control(command);
std::size_t bytes_readable = command.get();
std::cout << "It thinks I should read" << bytes_readable
<< " bytes" << std::endl;
} else {
std::cout << "There was an error" << std::endl;
}
}
void watch_descriptor(boost::asio::io_service& ios, int file_descriptor)
{
// Create the asio representation of the descriptor
stream_descriptor* desc = new stream_descriptor(ios);
desc->assign(file_descriptor);
// Try to read 0 bytes …Run Code Online (Sandbox Code Playgroud) 我有一个服务器应用程序,在dbus上创建一个总线,运行几分钟后,我得到了一个我从未见过的错误.你有什么想法吗?
*** longjmp causes uninitialized stack frame ***: /home/user/Workspace/DBus_Server/Debug/DBus_Server terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x37)[0x7f8d8911c7f7]
/lib/x86_64-linux-gnu/libc.so.6(+0xf8789)[0x7f8d8911c789]
/lib/x86_64-linux-gnu/libc.so.6(__longjmp_chk+0x33)[0x7f8d8911c6f3]
/usr/lib/x86_64-linux-gnu/libcurl-nss.so.4(+0xd795)[0x7f8d88272795]
/lib/x86_64-linux-gnu/libc.so.6(+0x36420)[0x7f8d8905a420]
/lib/x86_64-linux-gnu/libc.so.6(__poll+0x53)[0x7f8d890f9773]
/usr/lib/libdbus-c++-1.so.0(_ZN4DBus15DefaultMainLoop8dispatchEv+0x161)[0x7f8d89b6b481]
/usr/lib/libdbus-c++-1.so.0(_ZN4DBus13BusDispatcher5enterEv+0x63)[0x7f8d89b6c293]
/home/user/Workspace/DBus_Server/Debug/DBus_Server[0x401333]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7f8d8904530d]
/home/user/Workspace/DBus_Server/Debug/DBus_Server[0x4011c9]
Run Code Online (Sandbox Code Playgroud) 我写了一个简单的python程序来播放和暂停banshee音乐播放器.当它在我自己的机器上工作时,我无法将其连接到连接到同一路由器(LAN)的远程计算机.我编辑了远程机器的session.conf,添加以下行:
<listen>tcp:host=localhost,port=12434</listen>
Run Code Online (Sandbox Code Playgroud)
这是我的计划:
import dbus
bus_obj=dbus.bus.BusConnection("tcp:host=localhost,port=12434")
proxy_object=bus_obj.get_object('org.bansheeproject.Banshee',
'/org/bansheeproject/Banshee/PlayerEngine')
playerengine_iface=dbus.Interface(proxy_object,
dbus_interface='org.bansheeproject.Banshee.PlayerEngine')
var=0
while (var!="3"):
var=raw_input("\nPress\n1 to play\n2 to pause\n3 to exit\n")
if var=="1":
print "playing..."
playerengine_iface.Play()
elif var=="2":
print "pausing"
playerengine_iface.Pause()
Run Code Online (Sandbox Code Playgroud)
这是我尝试执行它时得到的结果
Traceback (most recent call last):
File "dbus3.py", line 4, in <module>
bus_obj=dbus.bus.BusConnection("tcp:host=localhost,port=12434")
File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 125, in __new__
bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoServer: Failed to connect to socket "localhost:12434" Connection refused
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?我应该编辑/usr/lib/python2.7/dist-packages/dbus/bus.py
更新:
好的,这是我添加的交易
<listen>tcp:host=192.168.1.7,port=12434</listen>
Run Code Online (Sandbox Code Playgroud)
到/etc/dbus-1/session.conf,然后重启,希望它会在重新启动时开始监听,它永远不会启动.它在加载屏幕上卡住,偶尔会出现以下文字的黑屏:
Pulseaudio Configured For Per-user Sessions Saned Disabled;edit/etc/default/saned
Run Code Online (Sandbox Code Playgroud)
所以,当我去ctrl + alt + f1时,将session.conf更改为原始状态并重启,它会正常启动. …
系统总线工作正常
(dbus-init-bus :system)
Run Code Online (Sandbox Code Playgroud)
应该返回nil.
但是,连接到会话总线
(dbus-init-bus :session)
Run Code Online (Sandbox Code Playgroud)
加薪
(dbus-error "No connection to bus" :session)
Run Code Online (Sandbox Code Playgroud)
qdbus在命令行中,两个总线都可以正常工作.如果有任何问题,它甚至可以在eshell中使用.
既不连接emacs也不emacs --daemon连接.
在OSX上是否有与Linux DBus相同的功能?我的意思是,OSX上默认有"消息总线"吗?
免责声明: OSX新手在这里.
我在arm上构建了一个根文件系统.它应该运行dbus-daemon和avahi-daemon,但是当我尝试运行时avahi-daemon
$ dbus-daemon --system
$ avahi-daemon
Run Code Online (Sandbox Code Playgroud)
我收到这条消息:
Found user 'avahi' (UID 4) and group 'avahi' (GID 4).
Successfully dropped root privileges.
avahi-daemon 0.6.28 starting up.
WARNING: No NSS support for mDNS detected, consider installing nss-mdns!
dbus_bus_request_name(): Connection ":1.0" is not allowed to own the service "org.freedesktop.Avahi" due to security policies in the configuration file
WARNING: Failed to contact D-Bus daemon.
avahi-daemon 0.6.28 exiting.
Run Code Online (Sandbox Code Playgroud)
怎么了?是关于dbus配置吗?
我在需要访问DBus的虚拟环境中运行应用程序(主要是与网络管理器交互).
我尝试使用easyinstall和pip安装Dbus-Python,但都失败了.
当我尝试这样做时:
(myvirtualenv)borrajax@borrajax-computer:~/Documents/Projects/VirtualEnvs/current_env$ bin/pip install dbus-python
Run Code Online (Sandbox Code Playgroud)
皮普对我大吼大叫:
Downloading/unpacking dbus-python
Downloading dbus-python-1.1.1.tar.gz (596kB): 596kB downloaded
Running setup.py egg_info for package dbus-python
Traceback (most recent call last):
File "<string>", line 16, in <module>
IOError: [Errno 2] No such file or directory: '/home/borrajax/Documents/Projects/VirtualEnvs/current_env/build/dbus-python/setup.py'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
IOError: [Errno 2] No such file or directory: '/home/borrajax/Documents/Projects/VirtualEnvs/current_env/build/dbus-python/setup.py'
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /home/borrajax/Documents/Projects/VirtualEnvs/current_env/build/dbus-python …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一些代码来使用DBUS与wpa_supplicant进行通信.当我在嵌入式系统(ARM)中工作时,我想避免使用Python或GLib.我想知道我是不是很愚蠢,因为我真的觉得没有关于D-Bus的清晰文档.即使使用官方文档,我发现文档的级别太高,或者显示的示例都使用了Glib!我看过的文档:http://www.freedesktop.org/wiki/Software/dbus
我发现了一篇关于在C中使用D-Bus的好文章:http://www.matthew.ath.cx/articles/dbus
但是,这篇文章已经很老了,还不够完整!我也找到了c ++ - dbus API,但在这里,我找不到任何文档!我一直在深入研究wpa_supplicant和NetworkManager源代码,但这真是一场噩梦!我一直在研究"低级D-Bus API",但这并没有告诉我如何从D-Bus消息中提取字符串参数!http://dbus.freedesktop.org/doc/api/html/index.html
下面是我编写的一些代码来测试,但我真的很难提取字符串值.很抱歉有很长的源代码,但如果有人想尝试...我的D-Bus配置似乎很好,因为它"已经"从wpa_supplicant捕获"StateChanged"信号,但无法打印状态:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <dbus/dbus.h>
//#include "wpa_supp_dbus.h"
/* Content of wpa_supp_dbus.h */
#define WPAS_DBUS_SERVICE "fi.epitest.hostap.WPASupplicant"
#define WPAS_DBUS_PATH "/fi/epitest/hostap/WPASupplicant"
#define WPAS_DBUS_INTERFACE "fi.epitest.hostap.WPASupplicant"
#define WPAS_DBUS_PATH_INTERFACES WPAS_DBUS_PATH "/Interfaces"
#define WPAS_DBUS_IFACE_INTERFACE WPAS_DBUS_INTERFACE ".Interface"
#define WPAS_DBUS_NETWORKS_PART "Networks"
#define WPAS_DBUS_IFACE_NETWORK WPAS_DBUS_INTERFACE ".Network"
#define WPAS_DBUS_BSSIDS_PART "BSSIDs"
#define WPAS_DBUS_IFACE_BSSID WPAS_DBUS_INTERFACE ".BSSID"
int running = 1;
void stopLoop(int sig)
{
running = 0;
}
void sendScan() …Run Code Online (Sandbox Code Playgroud)