Getting start with dbus in systemd (03) - sd-bus.h 使用例子 (systemd version>=221)

这篇博客介绍了在systemd版本大于等于221时如何开始使用sd-bus.h库。由于sd-bus是systemd从v221开始提供的,因此低于此版本的系统(如CentOS 219)不支持。文章引用了相关资源,指导读者了解和使用sd-bus。
摘要由CSDN通过智能技术生成

sd-bus.h 例子

注意:

sd-dbus 是systemd提供的lib,但是这个lib,只有在systemd>v221版本后才可以使用,centos 219版本太低,所以不能使用。

参考: http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html

#cat print-unit-path.c
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>

#include <systemd/sd-bus.h>
#define _cleanup_(f) __attribute__((cleanup(f)))

/* This is equivalent to:
 * busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 \
 *       org.freedesktop.systemd1.Manager GetUnitByPID $$
 *
 * Compile with 'cc -lsystemd print-unit-path.c'
 */

#define DESTINATION "org.freedesktop.systemd1"
#define PATH        "/org/freedesktop/systemd1"
#define INTERFACE   "org.freedesktop.systemd1.Manager"
#define MEMBER      "GetUnitByPID"

static int log_error(int error, const char *message) {
  fprintf(stderr, "%s: %s\n", message, strerror(-error));
  return error;
}

static int print_unit_path(sd_bus *bus) {
  _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值