X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Funit-name.c;h=8f6c28e86a84f6ea1fbcc9f6661e98952fa005c7;hb=1e5413f74faa378172d556e5dec35ab55de16bbf;hp=f2c30a6e4f7333c5e1f56d30ef331be423306d17;hpb=6c12b52e19640747e96f89d85422941a23dc6b29;p=elogind.git diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c index f2c30a6e4..8f6c28e86 100644 --- a/src/shared/unit-name.c +++ b/src/shared/unit-name.c @@ -26,11 +26,10 @@ #include "path-util.h" #include "util.h" #include "unit-name.h" +#include "def.h" #define VALID_CHARS \ - "0123456789" \ - "abcdefghijklmnopqrstuvwxyz" \ - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ + DIGITS LETTERS \ ":-_.\\" static const char* const unit_type_table[_UNIT_TYPE_MAX] = { @@ -467,6 +466,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; @@ -549,3 +564,30 @@ UnitType unit_name_to_type(const char *n) { return unit_type_from_string(e + 1); } + +int build_subslice(const char *slice, const char*name, char **subslice) { + char *ret; + + assert(slice); + assert(name); + assert(subslice); + + if (streq(slice, "-.slice")) + ret = strappend(name, ".slice"); + else { + char *e; + + e = endswith(slice, ".slice"); + if (!e) + return -EINVAL; + + ret = new(char, (e - slice) + 1 + strlen(name) + 6 + 1); + if (!ret) + return -ENOMEM; + + stpcpy(stpcpy(stpcpy(mempcpy(ret, slice, e - slice), "-"), name), ".slice"); + } + + *subslice = ret; + return 0; +}