Skip to content

Commit 180ffcc

Browse files
committed
instance: use mkdir_p helper
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: #31 Fixes: 7e5b324 ("instance: check length of names when creating cgroups") Signed-off-by: Daniel Golle <daniel@makrotopia.org>
1 parent 9493a3d commit 180ffcc

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

service/instance.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <syslog.h>
3131

3232
#include <libubox/md5.h>
33+
#include <libubox/utils.h>
3334

3435
#include "../procd.h"
3536
#include "../rcS.h"
@@ -570,22 +571,12 @@ instance_add_cgroup(const char *service, const char *instance)
570571
if (stat("/sys/fs/cgroup/cgroup.subtree_control", &sb))
571572
return -ENOENT;
572573

573-
mkdir(CGROUP_BASEDIR, 0700);
574-
575-
ret = snprintf(cgnamebuf, sizeof(cgnamebuf), "%s/%s", CGROUP_BASEDIR,
576-
service);
577-
if (ret >= sizeof(cgnamebuf))
578-
return -ENAMETOOLONG;
579-
580-
if (mkdir(cgnamebuf, 0700))
581-
return -EPERM;
582-
583574
ret = snprintf(cgnamebuf, sizeof(cgnamebuf), "%s/%s/%s", CGROUP_BASEDIR,
584575
service, instance);
585576
if (ret >= sizeof(cgnamebuf))
586577
return -ENAMETOOLONG;
587578

588-
if (mkdir(cgnamebuf, 0700))
579+
if (mkdir_p(cgnamebuf, 0700))
589580
return -EPERM;
590581

591582
if (strlen(cgnamebuf) + strlen(cgroup_procs) >= sizeof(cgnamebuf))

0 commit comments

Comments
 (0)