diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-07-02 01:35:08 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-07-02 01:48:55 +0200 |
commit | ede3a7967560506486e1e25d09ef4e74600851ff (patch) | |
tree | 8cfca3a63952ce9f83538085b4fe0e107fa49c09 | |
parent | cc23f9f17434aad3941dff3c20bce485b39ce47c (diff) |
core: split out unit bus path unescaping into unit_name_from_dbus_path()
-rw-r--r-- | src/core/manager.c | 13 | ||||
-rw-r--r-- | src/shared/unit-name.c | 16 | ||||
-rw-r--r-- | src/shared/unit-name.h | 1 |
3 files changed, 21 insertions, 9 deletions
diff --git a/src/core/manager.c b/src/core/manager.c index 42c9bcd48c..080561b5d1 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -1783,7 +1783,7 @@ int manager_loop(Manager *m) { } int manager_load_unit_from_dbus_path(Manager *m, const char *s, DBusError *e, Unit **_u) { - char *n; + _cleanup_free_ char *n = NULL; Unit *u; int r; @@ -1791,16 +1791,11 @@ int manager_load_unit_from_dbus_path(Manager *m, const char *s, DBusError *e, Un assert(s); assert(_u); - if (!startswith(s, "/org/freedesktop/systemd1/unit/")) - return -EINVAL; - - n = bus_path_unescape(s+31); - if (!n) - return -ENOMEM; + r = unit_name_from_dbus_path(s, &n); + if (r < 0) + return r; r = manager_load_unit(m, n, NULL, e, &u); - free(n); - if (r < 0) return r; diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c index f2c30a6e4f..7733aae0e7 100644 --- a/src/shared/unit-name.c +++ b/src/shared/unit-name.c @@ -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; diff --git a/src/shared/unit-name.h b/src/shared/unit-name.h index 88f2b83443..7f4ae56433 100644 --- a/src/shared/unit-name.h +++ b/src/shared/unit-name.h @@ -95,6 +95,7 @@ char *unit_name_from_path_instance(const char *prefix, const char *path, const c char *unit_name_to_path(const char *name); char *unit_dbus_path_from_name(const char *name); +int unit_name_from_dbus_path(const char *path, char **name); char *unit_name_mangle(const char *name); char *unit_name_mangle_with_suffix(const char *name, const char *suffix); |