Create unique service cgroup based on name:id

We want to have unique cgroups per instance.  I.e., a DHCP client for
eth0 should have its own cgroup separate from a DHCP client for eth1.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2020-04-11 21:50:38 +02:00
1 parent 91a9c83928
commit 25c194ef93
3 files changed
+7 -15

No files matched your search

+5 -13
View File
@@ -98,11 +98,11 @@ fail:
fclose(fp);
}
static int move_pid(char *group, char *name, int pid)
static int move_pid(char *group, char *name, char *id, int pid)
{
char path[256];
snprintf(path, sizeof(path), "/sys/fs/cgroup/%s/%s", group, name);
snprintf(path, sizeof(path), "/sys/fs/cgroup/%s/%s:%s", group, name, id);
if (mkdir(path, 0755) && errno != EEXIST)
return 1;
@@ -116,13 +116,11 @@ int cgroup_user(char *name)
if (!cg_init)
return 0;
return move_pid("finit/user", name, getpid());
return move_pid("finit/user", name, "0", getpid());
}
int cgroup_service(char *cmd, int pid)
int cgroup_service(char *nm, char *id, int pid)
{
char *nm;
if (!cg_init)
return 0;
@@ -131,13 +129,7 @@ int cgroup_service(char *cmd, int pid)
return 1;
}
nm = strrchr(cmd, '/');
if (nm)
nm++;
else
nm = cmd;
return move_pid("finit/system", nm, pid);
return move_pid("finit/system", nm, id, pid);
}
/**
+1 -1
View File
@@ -27,6 +27,6 @@
void cgroup_init (void);
int cgroup_user (char *name);
int cgroup_service (char *cmd, int pid);
int cgroup_service (char *cmd, char *id, int pid);
#endif /* FINIT_CGROUP_H_ */
+1 -1
View File
@@ -319,7 +319,7 @@ static int service_start(svc_t *svc)
sigprocmask(SIG_BLOCK, &nmask, &omask);
pid = fork();
cgroup_service(svc->cmd, pid);
cgroup_service(svc->name, svc->id, pid);
if (pid == 0) {
int status;