Getting start with dbus in systemd (02) - How to create a private dbus-daemon
Getting start with dbus in systemd (02)
创建一个私有的dbus-daemon (session)
环境
这里我们会有两个app: app1(client),app2(server), 然后,再启动一个“dbus-daemon (session)”
我们期望,app1 和 app2 之间的通信,可以使用 刚才启动的 “dbus-daemon”
代码在:
git clone https://github.com/muahao/hello-dbus3-0.1.git
环境:
- centos 7
依赖:
- dbus-x11-1.6.12-13.1.rhel7.x86_64 (提供dbus-launch)
- dbus-glib-0.100-7.1.rhel7.x86_64(代码实现依赖)
启动一个dbus-daemon (session)
方式1: 使用dbus-launch 创建一个dbus-daemon:
#yum install -y dbus-x11-1:1.6.12-13.1.alios7.x86_64
#dbus-launch
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-7Q7Spuq5IH,guid=079edc76e4c5c6433d3507855c5260ce
DBUS_SESSION_BUS_PID=121376
方式2: 手动启动
#DBUS_VERBOSE=1 dbus-daemon --session --print-address
unix:abstract=/tmp/dbus-jXwkggHTo2,guid=dc666ee7ba7ddf788efd8c485c526564
两个方式的目的,不仅仅是启动dbus-daemon, 更重要的是,获得address.
注意,这里会反馈一个地址, unix:abstract=/tmp/dbus-7Q7Spuq5IH,guid=079edc76e4c5c6433d3507855c5260ce
, 所以,你需要保证 你的环境变量 DBUS_SESSION_BUS_ADDRESS
的值就是这个地址。
其实dbus-daemon是有地址的,而且有一个环境变量来表示它--DBUS_SESSION_BUS_ADDRESS
,可以用命令env查看到。我们的程序,也就就是依靠这个环境变量来确认使用哪一个dbus-daemon的。
当我们登录进桌面环境的时候,系统启动脚本会调用到dbus-launch来启动一个dbus-daemon,同时会把这个dbus-daemon的地址赋予环境变量DBUS_SESSION_BUS_ADDRESS
。
#ps axu | grep dbus-daemon #新增一个dbus-daemon
dbus 91405 0.0 0.0 24312 2728 ? Ss Jan30 0:00 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root 121376 0.0 0.0 24312 228 ? Ss 10:43 0:00 /bin/dbus-daemon --fork --print-pid 4 --print-address 6 --session
设置环境变量DBUS_SESSION_BUS_ADDRESS
设置环境变量DBUS_SESSION_BUS_ADDRESS
到为刚才启动的dbus-daemon 的地址:
#DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-7Q7Spuq5IH,guid=079edc76e4c5c6433d3507855c5260ce
启动server:
这里会有一个报错:
#./example-service
Couldn't connect to session bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Fix: https://www.cnblogs.com/chutianyao/p/3770627.html
#eval `dbus-launch --sh-syntax`
正常运行:
server:
#./example-service
service running
client:
#./example-client
sum is 1099
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="data" direction="out" type="s"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface" direction="in" type="s"/>
<arg name="propname" direction="in" type="s"/>
<arg name="value" direction="out" type="v"/>
</method>
<method name="Set">
<arg name="interface" direction="in" type="s"/>
<arg name="propname" direction="in" type="s"/>
<arg name="value" direction="in" type="v"/>
</method>
<method name="GetAll">
<arg name="interface" direction="in" type="s"/>
<arg name="props" direction="out" type="a{sv}"/>
</method>
</interface>
<interface name="org.fmddlmyy.Test.Basic">
<method name="Add">
<arg name="arg0" type="i" direction="in"/>
<arg name="arg1" type="i" direction="in"/>
<arg name="ret" type="i" direction="out"/>
</method>
</interface>
</node>
Ref:
https://blog.csdn.net/jack0106/article/details/5588057
http://www.fmddlmyy.cn/text49.html
Getting start with dbus in systemd (02) - How to create a private dbus-daemon的更多相关文章
- Getting start with dbus in systemd (01) - Interface, method, path
Getting start with dbus in systemd (01) 基本概念 几个概念 dbus name: connetion: 如下,第一行,看到的就是 "dbus name ...
- Getting start with dbus in systemd (03) - sd-bus.h 使用例子 (systemd version>=221)
sd-bus.h 例子 注意: sd-dbus 是systemd提供的lib,但是这个lib,只有在systemd>v221版本后才可以使用,centos 219版本太低,所以不能使用. 参考: ...
- CentOS 7下关于systemd的一些唠叨话一:systemd的特点和使用
摘要 近年来,Linux 系统的 init 进程经历了两次重大的演进,传统的 sysvinit 已经逐渐淡出历史舞台,新的 UpStart 和 systemd 各有特点,越来越多的 Linux 发行版 ...
- 浅析 Linux 初始化 init 系统,第 1 部分: sysvinit 第 2 部分: UpStart 第 3 部分: Systemd
浅析 Linux 初始化 init 系统,第 1 部分: sysvinit 第 2 部分: UpStart 第 3 部分: Systemd http://www.ibm.com/developerw ...
- 【转发】CentOS 7 巨大变动之 systemd 取代 SysV的Init
1 systemd是什么 首先systmed是一个用户空间的程序,属于应用程序,不属于Linux内核范畴,Linux内核的主要特征在所有发行版中是统一的,厂商可以自由改变的是用户空间的应用程序. ...
- [Z] 深入浅出 Systemd
1. Systemd 的简介和特点 Systemd 是 Linux 系统中最新的初始化系统(init),它主要的设计目标是克服 sysvinit 固有的缺点,提高系统的启动速度.systemd 和 u ...
- D-Bus,kdbus和Binder
http://blog.sina.com.cn/s/blog_4af327e10101irie.html 材料来自:The unveiling of kdbus 和 Kdbus Details .后一 ...
- Systemd 添加自定义服务(开机自启动)
Systemd 简介:https://fedoraproject.org/wiki/Systemd/zh-cn 一.service unit 常用命令,以 mysql 服务为例 # 开机启动 syst ...
- CentOS 7 之 Systemd 入门教程:实战篇
开机启动对于那些支持 Systemd 的软件,安装的时候,会自动在/usr/lib/systemd/system目录添加一个配置文件. 如果你想让该软件开机启动,就执行下面的命令(以httpd.ser ...
随机推荐
- BZOJ1143:祭祀river(二分图求有向图的最大点独立集)
在遥远的东方,有一个神秘的民族,自称Y族.他们世代居住在水面上,奉龙王为神.每逢重大庆典, Y族都 会在水面上举办盛大的祭祀活动.我们可以把Y族居住地水系看成一个由岔口和河道组成的网络.每条河道连接着 ...
- 计算属性computed 与methods
你可能已经注意到我们可以通过调用表达式中的 method 来达到同样的效果: <p>Reversed message: "{{ reversedMessage() }}" ...
- asp.net Identity2 角色(Role)的使用(二)角色管理,角色控制器和视图
新建一个AdminViewModel 文件,建立视图模型类 public class RoleViewModel { public string Id { get; set; } [Required( ...
- 【转载】OAuth的机制原理讲解及开发流程
1.OAuth的简述 OAuth(Open Authorization,开放授权)是为用户资源的授权定义了一个安全.开放及简单的标准,第三方无需知道用户的账号及密码,就可获取到用户的授权信息,并且这是 ...
- arcgis for silverlight 相关学习资料整理
Arcgis Resources:http://resources.arcgis.com/en/home/ esri中文官方论坛:http://www.gisall.com/portal.php 爱吃 ...
- IDE工具的[多行光标编辑模式]
Sublime Text3:Ctrl+Alt+上下键 Eclipse:Shift+Alt+A,进入退出多光标模式 IDEA:Shift + ctrl + alt + 鼠标左键 收集链接 IDEA:ht ...
- 可视化工具Grafana部署
随着业务的越发复杂,对软件系统的要求越来越高,这意味着我们需要随时掌控系统的运行情况.因此,对系统的实时监控以及可视化展示,就成了基础架构的必须能力. Grafana官方网站 https://graf ...
- Activiti6.0教程 Eclipse安装Activiti Diagram插件(一)
最近这段时间打算出一个Activiti6.0的详细教程,Activiti作为一个流行的开源工作流引擎,正在不断发展,其6.0版本以API形式提供服务,而之前版本基本都是要求我们的应用以JDK方式与其交 ...
- docker速记
1.docker:一个轻量级的虚拟机.是一个容器 2.Linux系统包括—RedHat(商业版).Centos.Ubuntu 3.docker比作码头的集装箱,image镜像就是基石,images类似 ...
- 笔记——malloc、free、不同数据类型操作、.pyc文件、python安装第三方包、验证一个网站的所有链接有效性
C — malloc( ) and free( ) C 语言中使用malloc( )函数申请的内存空间,为什么一定要使用free释放? **malloc()函数功能:是从堆区申请一段连续的空间,函数结 ...