[systemd-devel] Multicast signaling with sd-bus questions

Gorman, Brian (Vancouver) bgorman at hp.com
Tue Jan 12 12:25:07 PST 2016


Hi Lennart, Do you have any suggestions on where to look to see a good example of how to have a process emit a signal to a different DBus listening process using sd-bus? If matching against ":1.x" is not advised I am assuming I should request a name? My initial attempt is:

/* Sender */
r = sd_bus_add_match(
            bus,
            slot,
            "type='signal',"
            "sender=Test.Blaster,"
            "interface='Japan.Reset',"
            "member='Test',"
            "path='/Japan'",
            my_signal_callback,
            my_user_data);
    
    fd = sd_bus_get_fd(bus);
    if (fd < 0)
        assert(0);
    FD_ZERO(&rd_fdset);
    FD_SET(fd, &rd_fdset);
    for (;;) {
        printf("enter select\n");
        select(fd +1, &rd_fdset, NULL, NULL,NULL);

/* End sender excerpt */

/* Transmitter code: */
    r = sd_bus_open_system(&bus);
    if (r < 0) {
        fprintf(stderr, "Failed to connect to bus: %s\n", strerror(-r));
        goto finish;
    }

    r = sd_bus_request_name(bus, "Test.Blaster", 0);
    
    if (r < 0) {
        fprintf(stderr, "Failed to get service name\n");
        goto finish;
    }
    
    sd_bus_emit_signal(bus,
                       "/Japan",
                       "/Japan.Reset.Test",
                       "Testing",
                       "Testing2");

/* End Transmitter excerpt */

It seems like the main problem here from looking at busctl is that no signal is getting emitted towards "Japan". Perhaps this is a problem with my /etc/dbus-1/system.d/*.conf file for my sender program?

Thanks and regards,
Brian

-----Original Message-----
From: Lennart Poettering [mailto:lennart at poettering.net] 
Sent: Tuesday, January 12, 2016 12:17 PM
To: Gorman, Brian (Vancouver)
Cc: Mantas Mikulėnas; systemd-devel at lists.freedesktop.org
Subject: Re: [systemd-devel] Multicast signaling with sd-bus questions

On Tue, 12.01.16 20:13, Gorman, Brian (Vancouver) (bgorman at hp.com) wrote:

> Hi Mantas
> 
> >>You really seem to be intent on using select() rather than an existing event loop or, at least, standard poll(); curious why.
> 
> There is existing code blocking on select, so it seems like the easiest way to crowbar DBus into my code.
> 
> >>Also, the 'sender' field is always a bus name (not sure but I think it's always the unique ":1.x" name), so "sender='testsignal'," would never match dbus-send (or anything at all).
> 
> Is there a way to “match” against “:1.x” with sd-bus i.e. instead of 
> “testsignal”? Is it advised to match against this, or should I have 
> the emitting program request a name?

Hmm? ":1.x" are so called "unique names, they are assigned automatically, and each peer on the bus has exactly one of these.

Since they are assigned automatically and effectively non-predictable it only makes to match against them if the peer in question first contacted you to let you know the unique name it has.

Lennart

--
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list