chiark / gitweb /
core: split out unit bus path unescaping into unit_name_from_dbus_path()
[elogind.git] / src / shared / unit-name.c
index f2c30a6e4f7333c5e1f56d30ef331be423306d17..7733aae0e72689192f7f4dad899271cea8f49226 100644 (file)
@@ -467,6 +467,22 @@ char *unit_dbus_path_from_name(const char *name) {
         return strappend("/org/freedesktop/systemd1/unit/", e);
 }
 
+int unit_name_from_dbus_path(const char *path, char **name) {
+        const char *e;
+        char *n;
+
+        e = startswith(path, "/org/freedesktop/systemd1/unit/");
+        if (!e)
+                return -EINVAL;
+
+        n = bus_path_unescape(e);
+        if (!n)
+                return -ENOMEM;
+
+        *name = n;
+        return 0;
+}
+
 char *unit_name_mangle(const char *name) {
         char *r, *t;
         const char *f;