summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-04-23 11:18:17 -0300
committerLennart Poettering <lennart@poettering.net>2013-04-23 16:00:32 -0300
commit70666185703ee173811d74b8cb0e0e47e2aa9b49 (patch)
tree625992935894795d94007ffa47446a9e5ebf820a
parent195f8e36122b83bbfef27bf63afe888e7101a320 (diff)
bus: add cal to determine machine id of an owner of a service
-rw-r--r--src/libsystemd-bus/bus-control.c32
-rw-r--r--src/systemd/sd-bus.h1
2 files changed, 33 insertions, 0 deletions
diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index e980bfc740..a4dc9bf511 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -344,3 +344,35 @@ int bus_remove_match_internal(sd_bus *bus, const char *match) {
"s",
match);
}
+
+int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine) {
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+ const char *mid;
+ int r;
+
+ if (!bus)
+ return -EINVAL;
+ if (!name)
+ return -EINVAL;
+
+ if (streq_ptr(name, bus->unique_name))
+ return sd_id128_get_machine(machine);
+
+ r = sd_bus_call_method(bus,
+ name,
+ "/",
+ "org.freedesktop.DBus.Peer",
+ "GetMachineId",
+ NULL,
+ &reply,
+ NULL);
+
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_read(reply, "s", &mid);
+ if (r < 0)
+ return r;
+
+ return sd_id128_from_string(mid, machine);
+}
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 8824efeaba..36fab9ffa1 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -179,6 +179,7 @@ int sd_bus_list_names(sd_bus *bus, char ***l);
int sd_bus_get_owner(sd_bus *bus, const char *name, char **owner);
int sd_bus_get_owner_uid(sd_bus *bus, const char *name, uid_t *uid);
int sd_bus_get_owner_pid(sd_bus *bus, const char *name, pid_t *pid);
+int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine);
/* Error structures */