instance: use mkdir_p helper main master
authorDaniel Golle <daniel@makrotopia.org>
Sat, 14 Feb 2026 20:43:13 +0000 (20:43 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Sat, 14 Feb 2026 21:16:47 +0000 (21:16 +0000)
Use mkdir_p() libubox helper function to create cgroup instance
directories. This simplifies instance_add_cgroup() and also avoids
returning an error in case the service directory already exists.

Fixes: openwrt/procd#31
Fixes: 7e5b324 ("instance: check length of names when creating cgroups")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
service/instance.c

index c559cdaa3dc48e89fda4a9ff2d77834f7ad26401..a456b8cef03c96f8ea48ef924cd1838ccebd19b8 100644 (file)
@@ -30,6 +30,7 @@
 #include <syslog.h>
 
 #include <libubox/md5.h>
+#include <libubox/utils.h>
 
 #include "../procd.h"
 #include "../rcS.h"
@@ -570,22 +571,12 @@ instance_add_cgroup(const char *service, const char *instance)
        if (stat("/sys/fs/cgroup/cgroup.subtree_control", &sb))
                return -ENOENT;
 
-       mkdir(CGROUP_BASEDIR, 0700);
-
-       ret = snprintf(cgnamebuf, sizeof(cgnamebuf), "%s/%s", CGROUP_BASEDIR,
-                      service);
-       if (ret >= sizeof(cgnamebuf))
-               return -ENAMETOOLONG;
-
-       if (mkdir(cgnamebuf, 0700))
-               return -EPERM;
-
        ret = snprintf(cgnamebuf, sizeof(cgnamebuf), "%s/%s/%s", CGROUP_BASEDIR,
                       service, instance);
        if (ret >= sizeof(cgnamebuf))
                return -ENAMETOOLONG;
 
-       if (mkdir(cgnamebuf, 0700))
+       if (mkdir_p(cgnamebuf, 0700))
                return -EPERM;
 
        if (strlen(cgnamebuf) + strlen(cgroup_procs) >= sizeof(cgnamebuf))