From 19b18afac965e38167ffd5fe84ba25c20e147897 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 7 Apr 2021 10:45:49 +0200 Subject: [PATCH] cgroup: Skip mkdir() and subtree control if group already exists - No point in doing it twice - Don't anger the gods (possible kernel bugs) Signed-off-by: Joachim Wiberg --- src/cgroup.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/cgroup.c b/src/cgroup.c index f495a8c5..d33f2a7d 100644 --- a/src/cgroup.c +++ b/src/cgroup.c @@ -86,16 +86,18 @@ static void group_init(char *path, int leaf, const char *cfg) { char *ptr, *s; - if (mkdir(path, 0755) && EEXIST != errno) { - _pe("Failed creating cgroup %s", path); - return; + if (!fisdir(path)) { + if (mkdir(path, 0755)) { + _pe("Failed creating cgroup %s", path); + return; + } + + /* enable detected controllers on domain groups */ + if (!leaf && fnwrite(controllers, "%s/cgroup.subtree_control", path)) + _pe("Failed enabling %s for %s", controllers, path); } - /* enable detected controllers on domain groups */ - if (!leaf && fnwrite(controllers, "%s/cgroup.subtree_control", path)) - _pe("Failed enabling %s for %s", controllers, path); - - if (!cfg) + if (!cfg || !cfg[0]) return; s = strdupa(cfg);