[systemd-devel] sd_bus_message_new_signal

Lennart Poettering lennart at poettering.net
Mon Jul 15 13:16:42 UTC 2019


On Mo, 15.07.19 13:55, Salman Ahmed (salman.isd at gmail.com) wrote:

> Hello,
> I am trying to send a signal using sdbus but I am not able to see anything
> on my dbus-monitor command:
> dbus-monitor "type='signal',interface='test.signal.Type'"
>
> code:
> sd_bus_error error = SD_BUS_ERROR_NULL;
> sd_bus_message *m = NULL;
> sd_bus *bus = NULL;
> int r;
>
> r = sd_bus_open_user(&bus);
> if (r < 0) {
>    fprintf(stderr, "Failed to connect to user bus: %s\n", strerror(-r));
> }
> r= sd_bus_message_new_signal(bus, &m, "/test/signal/Object",
> "test.signal.Type", "Test");
> if (r < 0) {
>    fprintf(stderr, "new signal failed: %s\n", strerror(-r));
> }
> r = sd_bus_send(bus, m , NULL);
> if (r < 0) {
>    fprintf(stderr, "bus send failed: %s\n", strerror(-r));
> }

sd-bus is fully asynchronous, it never blocks. This means that it
might not write the message to the socket yet when you just enqueue
it, and you might need to flush things, for example via
sd_bus_flush(). (or add the connection to an event loop so that the
work can be done for you automatically, scheduled by the event loop)

Lennart

--
Lennart Poettering, Berlin


More information about the systemd-devel mailing list