我目前正在与ConsoleKit和GDBus交谈。我使用ConsoleKit2 XML文件和gdbus-codegen生成代码。一切都很好。但是如何检查一个对象是否存在呢?例如,我想看看是否有一个/org/freedesktop/ConsoleKit/Session2 (只是一个例子,我知道我可以枚举see对象中的所有会话)。
我尝试使用org.freedesktop.DBus.Peer.Ping函数,但这将返回
dbus-send --system --print-reply --reply-timeout=2000 --type=method_call --dest=org.freedesktop.DBus /org/freedesktop/ConsoleKit/Seat1 org.freedesktop.DBus.Peer.Ping
Error org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 1 matched rules; type="method_call", sender=":1.168" (uid=1000 pid=18279 comm="dbus-send --system --print-reply --reply-timeout=2") interface="org.freedesktop.DBus.Peer" member="Ping" error name="(unset)" requested_reply="0" destination="org.freedesktop.DBus" (bus)发布于 2017-10-05 12:10:58
您有几个选项,按从最可取到最不可取的顺序排列:
GetSessions()枚举using对象中的所有会话。org.freedesktop.DBus.Error的错误而失败。Introspect()上调用/org/freedesktop/ConsoleKit方法并解析来自XML的<node>元素,以查看当前的对象路径层次结构。第一个选项可能是最容易实现的,并且是您打算如何使用ConsoleKit API。请注意,座位和会话编号不是确定性的,所以您不应该只在代码中硬编码会话对象路径,因为该路径在以后的引导中可能会更改。
还请注意,正如ConsoleKit网站所说的,ConsoleKit被弃用于系统d-logind,您应该考虑使用它。
https://stackoverflow.com/questions/46583906
复制相似问题