一个dbus daemon都一个配置文件来指定建立什么类型的dbus daemon,比如sysetm或者session类型,配置文件还会有一些资源限制,安全相关的参数设置等等

一.dbus daemon配置文件
我系统中的session的配置文件选项列出来

地址: /etc/dbus-1/session.conf

配置文件是xml格式

june@june:/etc/dbus-1$ cat session.conf
<!-- This configuration file controls the per-user-login-session message bus.Add a session-local.conf and edit that rather than changing this file directly. --><!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN""http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig> //root 元素<!-- Our well-known bus type, don't change this --><type>session</type>    //dbus daemon bus类型(session or system)<!-- If we fork, keep the user's original umask to avoid affectingthe behavior of child processes. --><keep_umask/>     // 如果设置了--fork,或者<fork>, 父子进程mask保持一致<listen>unix:tmpdir=/tmp</listen>    //设置监听地址,与命令--address一样功能<standard_session_servicedirs />   //标准的dbus service目录,就是一些按需启动的一些服务,//添加在这个目录,在linux系统中目录/usr/share/dbus-1/service<policy context="default">            //设置一些全制策略<allow own="*"/>                    //允许所有own<!-- Allow everything to be sent -->   <allow send_destination="*" eavesdrop="true"/>  //发送<!-- Allow everything to be received -->        <allow eavesdrop="true"/>                        //接收<!-- Allow anyone to own anything --><allow own="*"/>//这个是我手动添加的,无关紧要,就是为了体现配置, 允许所有类型的消息,dbus消息类型公有以下四种.<!-- All messages may be received by default --><allow receive_type="method_call"/><allow receive_type="method_return"/><allow receive_type="error"/><allow receive_type="signal"/></policy><!-- raise the service start timeout to 40 seconds as it can timeouton the live cd on slow machines --><limit name="service_start_timeout">60000</limit><!-- Config files are placed here that among other things, further restrict the above policy for specific services. --><includedir>session.d</includedir>    //这个指定目录,就是为添加配置所用,如果你想添加配置,即可在seesion.con添加//root 元素<!-- Our well-known bus type, don't change this --><type>session</type>    //dbus daemon bus类型(session or system)<!-- If we fork, keep the user's original umask to avoid affectingthe behavior of child processes. --><keep_umask/>     // 如果设置了--fork,或者<fork>, 父子进程mask保持一致<listen>unix:tmpdir=/tmp</listen>    //设置监听地址,与命令--address一样功能<standard_session_servicedirs />   //标准的dbus service目录,就是一些按需启动的一些服务,//添加在这个目录,在linux系统中目录/usr/share/dbus-1/service<policy context="default">            //设置一些全制策略<allow own="*"/>                    //允许所有own<!-- Allow everything to be sent -->   <allow send_destination="*" eavesdrop="true"/>  //发送<!-- Allow everything to be received -->        <allow eavesdrop="true"/>                        //接收<!-- Allow anyone to own anything --><allow own="*"/>//这个是我手动添加的,无关紧要,就是为了体现配置, 允许所有类型的消息,dbus消息类型公有以下四种.<!-- All messages may be received by default --><allow receive_type="method_call"/><allow receive_type="method_return"/><allow receive_type="error"/><allow receive_type="signal"/></policy><!-- raise the service start timeout to 40 seconds as it can timeouton the live cd on slow machines --><limit name="service_start_timeout">60000</limit><!-- Config files are placed here that among other things, further restrict the above policy for specific services. --><includedir>session.d</includedir>    //这个指定目录,就是为添加配置所用,如果你想添加配置,即可在seesion.con添加
                                      //也可以在这个目录下添加,建议在此,可以模块化管理,添加的文件必须以.conf结尾,否则不识别//也可以在这个目录下添加,建议在此,可以模块化管理,添加的文件必须以.conf结尾,否则不识别

<!-- This is included last so local configuration can override what's 
       in this standard file -->
  <include ignore_missing="yes">session-local.conf</include> //session 配置文件,如果没有就跳过,不报错
                                                              //如果ignore_missing="no", 配置文件不存在,会报错.

<include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include> //安全相关的配置,类似与防火墙

<!-- For the session bus, override the default relatively-low limits 
       with essentially infinite limits, since the bus is just running 
       as the user anyway, using up bus resources is not something we need 
       to worry about. In some cases, we do set the limits lower than 
       "all available memory" if exceeding the limit is almost certainly a bug, 
       having the bus enforce a limit is nicer than a huge memory leak. But the 
       intent is that these limits should never be hit. -->

//下面这些是资源的一些限制
  <!-- the memory limits are 1G instead of say 4G because they can't exceed 32-bit signed int max -->
  <limit name="max_incoming_bytes">1000000000</limit>
  <limit name="max_incoming_unix_fds">250000000</limit>
  <limit name="max_outgoing_bytes">1000000000</limit>
  <limit name="max_outgoing_unix_fds">250000000</limit>
  <limit name="max_message_size">1000000000</limit>
  <!-- We do not override max_message_unix_fds here since the in-kernel
       limit is also relatively low -->
  <limit name="service_start_timeout">120000</limit>  
  <limit name="auth_timeout">240000</limit>
  <limit name="pending_fd_timeout">150000</limit>
  <limit name="max_completed_connections">100000</limit>  
  <limit name="max_incomplete_connections">10000</limit>
  <limit name="max_connections_per_user">100000</limit>
  <limit name="max_pending_service_starts">10000</limit>
  <limit name="max_names_per_connection">50000</limit>
  <limit name="max_match_rules_per_connection">50000</limit>
  <limit name="max_replies_per_connection">50000</limit>
</busconfig>

下面举例测试一些规则:

前提条件: 1.在自己电脑上安装好dbus,一般不用装,系统与ui交互都需要D-Bus

2. 拷贝 DBus 实例 中的代码,然后编译
(最好看一下源代码的逻辑,做了什么,这样更有利于理解)

一.源代码编译:

june@june:~/document/comb$ gcc service.c -ldbus-1 -I/usr/include/dbus-1.0 -o service
june@june:~/document/comb$
june@june:~/document/comb$ gcc client.c -ldbus-1 -I/usr/include/dbus-1.0 -o client
june@june:~/document/comb$ ls
client  client.c  service  service.c
june@june:~/document/comb$ 

二.手动启动一个Dbus daemon

june@june:~/document/comb$ dbus-daemon --session --print-address --fork --print-pid
unix:abstract=/tmp/dbus-CSy0dphkTM,guid=24e009e82bece7928f58cc4b5b39c4f6
2900
june@june:~/document/comb$ 

三.关键的一步,需要把监听的address export出来(为什么要这么做呢,因为dbus_bus_get()获取连接的时候,会去找这个环境变量,来获取监听地址)

june@june:~/document/comb$ export  DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-CSy0dphkTM,guid=24e009e82bece7928f58cc4b5b39c4f6
june@june:~/document/comb$ 

四.运行,测试结果

june@june:~/document/comb$ ./service &        //放在后台做服务端
[1] 2903
june@june:~/document/comb$ path: /org/freedesktop/DBus
path: /org/freedesktop/DBusjune@june:~/document/comb$ ./client        //在前台运行,做请求端,client共做了两件事:
path: /org/freedesktop/DBus                //1. 发信号到 path=/hello interface=aa.bb.cc signal=alarm_test 且携带的信号内容为hello world!
path: /org/freedesktop/DBus                //2.调用add操作到bus name=hello.world.service path=/hello/world interface=hello.world method =add
path: /hello                                //? 为什么signal没有指定bus name呢,因为signal是广播,不过也有接口可以指定目的bus name的,那样就变为单播了.
recv param --: hello world!
path: /hello/world
service: add  function
 a(100) + b(99) = 199
june@june:~/document/comb$ //放在后台做服务端
[1] 2903
june@june:~/document/comb$ path: /org/freedesktop/DBus
path: /org/freedesktop/DBusjune@june:~/document/comb$ ./client        //在前台运行,做请求端,client共做了两件事:
path: /org/freedesktop/DBus                //1. 发信号到 path=/hello interface=aa.bb.cc signal=alarm_test 且携带的信号内容为hello world!
path: /org/freedesktop/DBus                //2.调用add操作到bus name=hello.world.service path=/hello/world interface=hello.world method =add
path: /hello                                //? 为什么signal没有指定bus name呢,因为signal是广播,不过也有接口可以指定目的bus name的,那样就变为单播了.
recv param --: hello world!
path: /hello/world
service: add  function
 a(100) + b(99) = 199
june@june:~/document/comb$

五.添加一个安全策略,禁止发送到特定的目的bus name

编写/etc/dbus-1/session.conf

</policy>上面一行添加<deny send_destination="hello.world.service"/> 禁止发送消息hello.world.service

发送SIGHUP信号到dbus-daemon,可以其重新加载配置 ,在DBus daemon 启动中提到过

在这里禁止发送消息到hello.world.service,那不管是signal还是method都将失败.

june@june:~/document/comb$ kill -1 2900
june@june:~/document/comb$ psPID TTY          TIME CMD2305 pts/0    00:00:00 bash2965 pts/0    00:00:00 service2979 pts/0    00:00:00 ps
june@june:~/document/comb$ ./client
paramter type errora(100) + b(99) = 159115060
june@june:~/document/comb$

如果想看spec文档,请访问:spec文档网址

D-Bus 配置相关(四)相关推荐

  1. 想学linux需要的电脑配置相关

    开始学linux了,加油!!! 我是跟着正点原子的视频学的,左神第一期讲--做linux开发需要的电脑配置 左神自己的配置以及他推荐的配置如下: CPU 性能越强越好,cpu的核越多越好 内存 推荐1 ...

  2. 台式机计算机型号怎么查,电脑配置怎么查询?笔记本台式机查询电脑配置的四种方法...

    电脑配置怎么查询?虽然说现在网络非常的发达,但是并不是每个人都是电脑专家,还有一些不怎么接触电脑的小白用户,对于电脑配置怎么查询并不了解.今天智能手机网就为大家带来了电脑配置查询的具体方法,一起来瞧一 ...

  3. 16. php-fpm配置相关

    [toc] php-fpm配置相关 一.php-fpm配置 和LAMP不同的是,在LNMP架构中,php-fpm作为独立的一个服务存在,既然是独立服务,那么它必然有自己的配置文件.php-fpm的配置 ...

  4. 小程序配置服务器四个怎么填,小程序配置服务器四个怎么填

    小程序配置服务器四个怎么填 内容精选 换一换 弹性负载均衡(Elastic Load Balance,简称ELB)是将访问流量根据分配策略分发到后端多台服务器云主机的流量分发控制服务. 简要介绍Bre ...

  5. java Bus配置

    java Bus配置 springCloud学习记录 SpringCloud Alibaba Bus(消息总线) 服务端 pom yml 启动类 客户端 pom yml 启动类 方法类获取配置信息 s ...

  6. Linux网络属性配置相关命令

    Linux网络属性配置相关命令: 前言: Linux属性配置可以分为两类.一类通过命令配置,另一类通过修改配置文件配置. Linux属性配置的相关命令可以分为三大类: 一.ifcfg命令家族:①ifc ...

  7. memcached的基本命令(安装、卸载、启动、配置相关)

    memcached的基本命令(安装.卸载.启动.配置相关): -p 监听的端口  -l 连接的IP地址, 默认是本机   -d start 启动memcached服务  -d restart 重起me ...

  8. Docker部署配置相关使用总结

    Docker部署配置相关使用总结 创建并启动容器 使用 docker run 命令来创建并启动一个容器: $ docker run -it centos /bin/echo 'hello world' ...

  9. 计算机的相关配置信息,win7系统查看电脑配置相关信息的方案介绍

    win7系统使用久了,好多网友反馈说win7系统查看电脑配置相关信息的问题,非常不方便.有什么办法可以永久解决win7系统查看电脑配置相关信息的问题,面对win7系统查看电脑配置相关信息的图文步骤非常 ...

  10. nodeJs配置相关以及JSON.parse

    nodeJs配置相关 实际上说应用相关更好吧,我不是很懂. 今天在工作中,被同事解决了一个问题,虽然多花了一些额外时间,但长痛不如短痛嘛 实际上的问题就是npm run target等命令可以,但是n ...

最新文章

  1. 一个AI产品经理怎么看AI的发展
  2. cryptogen (2)generate 生成证书再举例
  3. Mysql8.0注意url变更写法
  4. python实现http请求并发_Python使用grequests并发发送请求
  5. Apple’s current market value is more than two trillion
  6. android sdk更新后出现please update ADT to the latest ve
  7. GoldenGate 12.3 MA架构介绍系列(4)–Restful API介绍
  8. Cisco路由器上传和下载IOS
  9. k8s集群部署二(自签TLS证书)
  10. 最新黑马软件测试全套视频教程
  11. vue中SM4加密解密(js部分)
  12. 阿里云和Azure ICON图标矢量素材分享
  13. MIMO信道容量仿真MATLAB,MIMO系统的信道容量分析 及Matlab仿真
  14. 在VMware上安装Android虚拟机
  15. java kryo_通过Kryo的序列化方式提升Netty性能
  16. linux音乐应用程序,适用于节拍,循环,录音的最佳免费Linux音乐制作应用程序 | MOS86...
  17. 纳滤膜分离技术用于制药提纯精制处理 稳定可靠
  18. 基于Android+Python Flask框架实现的智慧记单词APP设计
  19. excel减法函数_数据工作中常用到的EXCEL技巧之文本分析类
  20. TDengine 单节点Cluster not ready( 群集未就绪) 异常问题分析及解决方案

热门文章

  1. Excel表格数据转为json格式数据
  2. 如何判断js数组是否为空
  3. 城乡儿童阅读鸿沟仍明显 近九成乡村儿童阅读缺乏家长陪伴
  4. 3D 打印切片定义,什么是切片
  5. 流媒体系统的开发跟运维
  6. 如何在线替换并调试网页上的 JS 代码
  7. php 网页如何实现点击,在JS中如何实现网页自动秒杀点击(详细教程)
  8. “8.5折购买商品”和“原价购买得12倍积分”,哪个更划算?
  9. oracle ORA-01704: string literal too long
  10. 敏捷教练----Scrum-概述