Start the systemd service from a C / C ++ application or call the D-Bus service

I have a .service for a process that I do not want to start at boot time, but call it somehow from another already running application at a given time.

Another option is to place the D-Bus (I use glib dbus in my applications) in the file / usr / share / dbus -1 / services and somehow call it from my application. In addition, I am also unable to do this.

Say 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 the command line:

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

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

+7
source share
2 answers

The 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.

+4
source

It was hard for me to do the same. Discovery: G_BUS_NAME_WATCHER_FLAGS_AUTO_START authorizes it.

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

All Articles