From ef5c570edfd8afb20e3b04d3711e111a1dea0548 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 3 Sep 2015 18:23:26 +0200 Subject: util: document why parse_uid() returns ENXIO parse_uid() returns EINVAL for invalid strings, but ENXIO for the (uid_t) -1 user ids in order to distinguish these two cases. Document this. --- src/test/test-util.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/test') diff --git a/src/test/test-util.c b/src/test/test-util.c index dff38ab6f6..10d8d210d5 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -282,6 +282,9 @@ static void test_parse_uid(void) { r = parse_uid("65535", &uid); assert_se(r == -ENXIO); + + r = parse_uid("asdsdas", &uid); + assert_se(r == -EINVAL); } static void test_safe_atou16(void) { -- cgit v1.2.3-54-g00ecf From 5f4c5fef66581383ee852b301db67f687663004c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 3 Sep 2015 19:50:37 +0200 Subject: cgroup: always read the supported controllers from the root cgroup of the local container Otherwise we might end up thinking that we support more controllers than actually enabled for the container we are running in. --- src/basic/cgroup-util.c | 12 ++++++++++-- src/test/test-cgroup-util.c | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src/test') diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index fe8750d0f3..388bd629ee 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -1981,14 +1981,22 @@ int cg_mask_supported(CGroupMask *ret) { if (unified < 0) return unified; if (unified > 0) { - _cleanup_free_ char *controllers = NULL; + _cleanup_free_ char *root = NULL, *controllers = NULL, *path = NULL; const char *c; /* In the unified hierarchy we can read the supported * and accessible controllers from a the top-level * cgroup attribute */ - r = read_one_line_file("/sys/fs/cgroup/cgroup.controllers", &controllers); + r = cg_get_root_path(&root); + if (r < 0) + return r; + + r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, root, "cgroup.controllers", &path); + if (r < 0) + return r; + + r = read_one_line_file(path, &controllers); if (r < 0) return r; diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c index ecc9d70bf4..ff7e45901c 100644 --- a/src/test/test-cgroup-util.c +++ b/src/test/test-cgroup-util.c @@ -295,6 +295,17 @@ static void test_shift_path(void) { test_shift_path_one("/foobar/waldo", "/fuckfuck", "/foobar/waldo"); } +static void test_mask_supported(void) { + + CGroupMask m; + CGroupController c; + + assert_se(cg_mask_supported(&m) >= 0); + + for (c = 0; c < _CGROUP_CONTROLLER_MAX; c++) + printf("'%s' is supported: %s\n", cgroup_controller_to_string(c), yes_no(m & CGROUP_CONTROLLER_TO_MASK(c))); +} + int main(void) { test_path_decode_unit(); test_path_get_unit(); @@ -309,6 +320,7 @@ int main(void) { test_controller_is_valid(); test_slice_to_path(); test_shift_path(); + test_mask_supported(); return 0; } -- cgit v1.2.3-54-g00ecf From 348637b28a6253591a5899665d3cde6d8d71d118 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 3 Sep 2015 20:11:58 +0200 Subject: test: add one more test case for parse_pid() --- src/test/test-util.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/test') diff --git a/src/test/test-util.c b/src/test/test-util.c index 10d8d210d5..8ceb71f22a 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -270,6 +270,9 @@ static void test_parse_pid(void) { r = parse_pid("0xFFFFFFFFFFFFFFFFF", &pid); assert_se(r == -ERANGE); assert_se(pid == 65); + + r = parse_pid("junk", &pid); + assert_se(r == -EINVAL); } static void test_parse_uid(void) { -- cgit v1.2.3-54-g00ecf