HALF ECHO LEARN / REFERENCE COLLECTION

v262.2

src/libsystemd/sd-bus/bus-control.c

41,423 bytesGit mode 100644Download original fileLGPL-2.1-or-later

Git blob: 5368024f28cfd4b772b4fb690220f7d217673834

Lines 1001–1128 of 1,128

                        &reply);
        if (r < 0)
                return r;
 
        /* If the caller asked for it, return the read counter of the reply */
        if (ret_counter)
                *ret_counter = reply->read_counter;
 
        return r;
}
 
int bus_add_match_internal_async(
                sd_bus *bus,
                sd_bus_slot **ret_slot,
                const char *match,
                sd_bus_message_handler_t callback,
                void *userdata,
                uint64_t timeout_usec) {
 
        _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
        const char *e;
        int r;
 
        assert(bus);
 
        if (!bus->bus_client)
                return -EINVAL;
 
        e = append_eavesdrop(bus, match);
 
        r = sd_bus_message_new_method_call(
                        bus,
                        &m,
                        "org.freedesktop.DBus",
                        "/org/freedesktop/DBus",
                        "org.freedesktop.DBus",
                        "AddMatch");
        if (r < 0)
                return r;
 
        r = sd_bus_message_append(m, "s", e);
        if (r < 0)
                return r;
 
        return sd_bus_call_async(
                        bus,
                        ret_slot,
                        m,
                        callback,
                        userdata,
                        timeout_usec);
}
 
int bus_remove_match_internal(
                sd_bus *bus,
                const char *match) {
 
        const char *e;
 
        assert(bus);
        assert(match);
 
        if (!bus->bus_client)
                return -EINVAL;
 
        e = append_eavesdrop(bus, match);
 
        /* Fire and forget */
 
        return sd_bus_call_method_async(
                        bus,
                        NULL,
                        "org.freedesktop.DBus",
                        "/org/freedesktop/DBus",
                        "org.freedesktop.DBus",
                        "RemoveMatch",
                        NULL,
                        NULL,
                        "s",
                        e);
}
 
_public_ int sd_bus_get_name_machine_id(sd_bus *bus, const char *name, sd_id128_t *ret) {
        _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL, *m = NULL;
        const char *mid;
        int r;
 
        assert_return(bus, -EINVAL);
        assert_return(bus = bus_resolve(bus), -ENOPKG);
        assert_return(name, -EINVAL);
        assert_return(ret, -EINVAL);
        assert_return(!bus_origin_changed(bus), -ECHILD);
        assert_return(service_name_is_valid(name), -EINVAL);
 
        if (!bus->bus_client)
                return -EINVAL;
 
        if (!BUS_IS_OPEN(bus->state))
                return -ENOTCONN;
 
        if (streq_ptr(name, bus->unique_name))
                return sd_id128_get_machine(ret);
 
        r = sd_bus_message_new_method_call(
                        bus,
                        &m,
                        name,
                        "/",
                        "org.freedesktop.DBus.Peer",
                        "GetMachineId");
        if (r < 0)
                return r;
 
        r = sd_bus_message_set_auto_start(m, false);
        if (r < 0)
                return r;
 
        r = sd_bus_call(bus, m, 0, NULL, &reply);
        if (r < 0)
                return r;
 
        r = sd_bus_message_read(reply, "s", &mid);
        if (r < 0)
                return r;
 
        return sd_id128_from_string(mid, ret);
}