gpt4 book ai didi

c - dbus 示例 - on_name_lost 位于 on_name_acquired 之后

转载 作者:行者123 更新时间:2023-11-30 19:30:52 25 4
gpt4 key购买 nike

我能够使用 dbus 作为客户端,但是如果我编译 https://github.com/bratsche/glib/blob/master/gio/tests/gdbus-example-server.con_name_acquired 回调被调用,并且在 on_name_lost 回调被调用之后。我所做的唯一更改是使用 G_BUS_TYPE_SYSTEM 而不是 G_BUS_TYPE_SESSION

我只是猜测这是一些身份验证问题。

最佳答案

与 session 总线不同,系统总线具有安全策略,可防止任意进程在总线上声明任意众所周知的名称。您需要安装configuration file让系统总线允许您的服务拥有一个名称:

Rules with the own or own_prefix attribute are checked when aconnection attempts to own a well-known bus names. As a special case,own="*" matches any well-known bus name. The well-known session busnormally allows any connection to own any name, while the well-knownsystem bus normally does not allow any connection to own any name,except where allowed by further configuration. System services thatwill own a name must install configuration that allows them to do so,usually via rules of the form <policy user="some-system-user"><allow own="…"/></policy>.

这意味着安装如下所示的配置文件 /usr/share/dbus-1/system.d/org.mydomain.MyService1.conf :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- Only my-service-user can own the service -->
<policy user="my-service-user">
<allow own="org.mydomain.MyService1"/>
</policy>

<!-- Anyone can send messages to the service -->
<policy context="default">
<allow send_destination="org.mydomain.MyService1"/>
</policy>
</busconfig>

然后,您必须以my-service-user运行您的服务进程。用户。

D-Bus API design tutorial section on security policies是相关阅读。

关于c - dbus 示例 - on_name_lost 位于 on_name_acquired 之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49876784/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com