systemd 221版本中的总线API。当我在系统总线请求一个对象名称时,会显示“权限被拒绝”的错误。我正在以root身份运行输出文件。“sd_bus_request_name(bus, "net.poettering.Calculator", 0)”这一行抛出了一个错误:“无法获取服务名称:权限被拒绝”。
我认为root应该有权限获取对象名称。有谁知道如何解决这个问题吗?
提前致谢。
以下是示例代码,取自http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html:
int main(int argc, char *argv[]) {
sd_bus_slot *slot = NULL;
sd_bus *bus = NULL;
int r;
r = sd_bus_default_system(&bus);
if (r < 0) {
fprintf(stderr, "Failed to connect to system bus: %s\n", strerror(-r));
goto finish;
}
/* Install the object */
r = sd_bus_add_object_vtable(bus,
&slot,
"/net/poettering/Calculator",
"net.poettering.Calculator", /* interface name */calculator_vtable,
NULL);
if (r < 0) {
fprintf(stderr, "Failed to issue method call: %s\n", strerror(-r));
goto finish;
}
/* Take a well-known service name so that clients can find us */
r = sd_bus_request_name(bus, "net.poettering.Calculator", 0);
if (r < 0) {
fprintf(stderr, "Failed to acquire service name: %s\n", strerror(-r));
goto finish;
}