bus-util: introduce bus_get_instance_id()

This commit is contained in:
Mike Yuan
2025-01-13 21:52:19 +01:00
parent af0e10354e
commit a9a8d2e12f
2 changed files with 25 additions and 0 deletions
+23
View File
@@ -905,6 +905,29 @@ int bus_query_sender_pidref(
return bus_creds_get_pidref(creds, ret);
}
int bus_get_instance_id(sd_bus *bus, sd_id128_t *ret) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
int r;
assert(bus);
assert(ret);
r = sd_bus_call_method(bus,
"org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "GetId",
/* error = */ NULL, &reply,
NULL);
if (r < 0)
return r;
const char *id;
r = sd_bus_message_read_basic(reply, 's', &id);
if (r < 0)
return r;
return sd_id128_from_string(id, ret);
}
static const char* const bus_transport_table[] = {
[BUS_TRANSPORT_LOCAL] = "local",
[BUS_TRANSPORT_REMOTE] = "remote",
+2
View File
@@ -81,4 +81,6 @@ int bus_register_malloc_status(sd_bus *bus, const char *destination);
int bus_creds_get_pidref(sd_bus_creds *c, PidRef *ret);
int bus_query_sender_pidref(sd_bus_message *m, PidRef *ret);
int bus_get_instance_id(sd_bus *bus, sd_id128_t *ret);
const char* bus_transport_to_string(BusTransport transport) _const_;