从C / C ++应用程序启动systemd服务或调用D-Bus服务 [英] Start systemd service from C/C++ application or call a D-Bus service

查看:215
本文介绍了从C / C ++应用程序启动systemd服务或调用D-Bus服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a .service for a process that i don't want to start at boot-time, but to call it somehow from another already running application, at a given time.

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

The other option would be to put a D-Bus (i'm using glib dbus in my apps ) service file in /usr/share/dbus-1/services and somehow call it from my application. Also, i don't manage to do this either.

比方说,我的dbus服务文件来自 / usr / share / dbus-1 /服务 com.callThis.service
,我从 / lib / systemd / system中获得的主要服务文件是com.startThis.service

Let's say that my dbus service file from /usr/share/dbus-1/services is com.callThis.service and my main service file from /lib/systemd/system is com.startThis.service

如果我从命令行进行简单的自省:

If i run a simple introspect from command line:

/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 ++代码中实现这一目标。

the D-Bus service file will get called and it will start what is in the Exec ( com.starThis ). The problem is that i want to achieve this from C/C++ code using D-Bus glib.

推荐答案

的组合href = http://developer.gnome.org/gio/2.30/GDBusConnection.html#g-dbus-connection-send-message rel = noreferrer> g_dbus_connection_send_message g_dbus_message_new_method_call g_dbus_message_new_signal 应该是您想要的。

A combination of g_dbus_connection_send_message with g_dbus_message_new_method_call or g_dbus_message_new_signal should be what you are looking for.

这篇关于从C / C ++应用程序启动systemd服务或调用D-Bus服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆