【问题标题】:Start systemd service from C/C++ application or call a D-Bus service从 C/C++ 应用程序启动 systemd 服务或调用 D-Bus 服务
【发布时间】:2012-11-30 08:29:42
【问题描述】:

我有一个 .service 用于我不想在启动时启动的进程,而是在给定时间从另一个已经运行的应用程序中以某种方式调用它。

另一种选择是将 D-Bus(我在我的应用程序中使用 glib dbus)服务文件放在 /usr/share/dbus-1/services 中,并以某种方式从我的应用程序中调用它。另外,我也不会这样做。

假设我来自/usr/share/dbus-1/services 的dbus 服务文件是com.callThis.service 和我来自/lib/systemd/system is com.startThis.service的主要服务文件

如果我从命令行运行一个简单的内省:

/home/root # dbus-send --session --type=method_call --print-reply \
--dest=com.callThis  /com/callThis org.freedesktop.DBus.Introspectable.Introspect

D-Bus 服务文件将被调用并启动 Exec ( com.starThis ) 中的内容。问题是我想使用 D-Bus glib 从 C/C++ 代码中实现这一点。

【问题讨论】:

标签: unix service process dbus systemd


【解决方案1】:

g_dbus_connection_send_messageg_dbus_message_new_method_callg_dbus_message_new_signal 的组合应该是您正在寻找的。​​p>

【讨论】:

    【解决方案2】:

    我在做同样的事情时遇到了麻烦。发现:G_BUS_NAME_WATCHER_FLAGS_AUTO_START 解决它。

    g_bus_watch_name(G_BUS_TYPE_SYSTEM, "com.mydbus.listen",
          G_BUS_NAME_WATCHER_FLAGS_AUTO_START, xOnNameAppeared, xOnNameVanished,
          this, nullptr);
    

    【讨论】:

      猜你喜欢
      • 2018-04-29
      • 2016-12-02
      • 2016-04-10
      • 2018-10-04
      • 1970-01-01
      • 1970-01-01
      • 2019-01-19
      • 1970-01-01
      相关资源
      最近更新 更多