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 ...
随机推荐
- 并不对劲的bzoj5020:loj2289:p4546:[THUWC2017]在美妙的数学王国中畅游
题目大意 有一个n(\(n\leq 10^5\))个点的森林,每个点\(u\)上有个函数\(f_u(x)\),是形如\(ax+b\)或\(e^{ax+b}\)或\(sin(ax+b)\)的函数,保证当 ...
- Ruby: Call the system and get system information.
1. Kill the task cmd2="taskkill /F /IM typeperf.exe"stdout2=%x{#{cmd2}} 2. Start counters: ...
- 无参数的lambda匿名函数
lambda 语法: lambda [arg1[,arg2,arg3....argN]]:expression 1.单个参数的: g = lambda x:x*2 print g(3) 结果是6 2. ...
- lua 与C通过c api传递table
此文转自http://blog.csdn.net/perfect2011/article/details/19200511(感谢...) 首先了解下c++与lua之间的通信: 假设在一个lua文件中有 ...
- CGAN 论文笔记
<Conditional Generative Adversarial Nets>: 发表于2014 computer Science.作者提出了最简单的条件控制GAN模型,在D和G两个模 ...
- 01_传智播客iOS视频教程_课程介绍与知识点回顾
OC语法中static关键字不能修饰属性,也不能修饰方法,只能修饰方法中的局部变量.static修饰局部变量之后把局部变量变成静态变量.当方法执行完之后这个变量不会被回收.下次再执行这个方法的时候这个 ...
- Linq list 排序,Dictionary 排序
C# 对List成员排序的简单方法 http://blog.csdn.net/wanzhuan2010/article/details/6205884 LINQ之路系列博客导航 http://www. ...
- P4575 [CQOI2013]图的逆变换
传送门 如果新的图里存在边\((u,v)\),那么说明原图中\(u\)的终点和\(v\)的起点是同一个点 于是可以对新图中的每个点维护它的起点和终点,如果有一条边就把对应两个应该相等的点用并查集连起来 ...
- 一文了解H5照片上传过程
一.选择拍照或文件 HTML: 使用<input>标签, type设为"file"选择文件, accept设为"image/*"选择文件为图片类型和 ...
- USACO Training3.3 A Game【区间Dp】 By cellur925
题目传送门 一股浓浓的博弈论香气...然而本蒟并不会博弈论. 开始用双端队列+假的dp水过了24pts水数据. 其实是布星的,两人都绝顶聪明会深谋远虑不像我只看眼前,所以上述算法错误. 正解:区间dp ...