diff options
| author | Daniel Golle | 2026-02-14 20:43:13 +0000 |
|---|---|---|
| committer | Daniel Golle | 2026-02-14 21:16:47 +0000 |
| commit | 180ffccf79d1a1a2c3eb644e26f6d87b1cbcfffd (patch) | |
| tree | 0b4f98ada352387c4a097c1e1093f05a007dd49c | |
| parent | 9493a3dcb48b9b3e197e9edfc37304fcd1b5acae (diff) | |
| download | procd-master.tar.gz | |
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>
| -rw-r--r-- | service/instance.c | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/service/instance.c b/service/instance.c index c559cda..a456b8c 100644 --- a/service/instance.c +++ b/service/instance.c @@ -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)) |