core: split out unit bus path unescaping into unit_name_from_dbus_path()
This commit is contained in:
parent
cc23f9f174
commit
ede3a79675
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue