X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fcgroup-util.c;h=a48b312018c26d420a1c1a10a0509fa1fd84cc8b;hb=c074ec090d670938ca6c70ff82fd039359499705;hp=2654efa1ceb279ac24c0beb124df534a6fdee4ac;hpb=8a6fd3c58501b9f27036a217b00f4fd9393731f6;p=elogind.git diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index 2654efa1c..a48b31201 100644 --- a/src/shared/cgroup-util.c +++ b/src/shared/cgroup-util.c @@ -488,7 +488,7 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch if (_unlikely_(!good)) { int r; - r = path_is_mount_point("/sys/fs/cgroup", false); + r = path_is_mount_point("/sys/fs/cgroup", 0); if (r < 0) return r; if (r == 0) @@ -1153,7 +1153,7 @@ int cg_path_decode_unit(const char *cgroup, char **unit){ c = strndupa(cgroup, n); c = cg_unescape(c); - if (!unit_name_is_valid(c, TEMPLATE_INVALID)) + if (!unit_name_is_valid(c, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE)) return -ENXIO; s = strdup(c); @@ -1180,7 +1180,7 @@ static bool valid_slice_name(const char *p, size_t n) { c = cg_unescape(buf); - return unit_name_is_valid(c, TEMPLATE_INVALID); + return unit_name_is_valid(c, UNIT_NAME_PLAIN); } return false; @@ -1637,28 +1637,41 @@ bool cg_controller_is_valid(const char *p, bool allow_named) { int cg_slice_to_path(const char *unit, char **ret) { _cleanup_free_ char *p = NULL, *s = NULL, *e = NULL; const char *dash; + int r; assert(unit); assert(ret); - if (!unit_name_is_valid(unit, TEMPLATE_INVALID)) + if (streq(unit, "-.slice")) { + char *x; + + x = strdup(""); + if (!x) + return -ENOMEM; + *ret = x; + return 0; + } + + if (!unit_name_is_valid(unit, UNIT_NAME_PLAIN)) return -EINVAL; if (!endswith(unit, ".slice")) return -EINVAL; - p = unit_name_to_prefix(unit); - if (!p) - return -ENOMEM; + r = unit_name_to_prefix(unit, &p); + if (r < 0) + return r; dash = strchr(p, '-'); while (dash) { _cleanup_free_ char *escaped = NULL; char n[dash - p + sizeof(".slice")]; - strcpy(stpncpy(n, p, dash - p), ".slice"); + if (isempty(dash + 1)) + return -EINVAL; - if (!unit_name_is_valid(n, TEMPLATE_INVALID)) + strcpy(stpncpy(n, p, dash - p), ".slice"); + if (!unit_name_is_valid(n, UNIT_NAME_PLAIN)) return -EINVAL; escaped = cg_escape(n);