Package: libcgroup1
Version: 0.41-8+deb9u1
Severity: important

Dear Maintainer,

The cgrulesengd is moving only the thread with the same PID/TID to the
cgroup set on /etc/cgrules.conf. That is a problem because
the process is not completely moved to a cgroup, but only the fisrt thread
of the process.

There is same bug in redhat, which is resolved - https://bugzilla.redhat.com/show_bug.cgi?id=1284495. I build package with redhat patch and seems to move all threads to configured cgroup. See attached patch.
Would you include provided patch in debian version of package.

Regards,
-- Georgi Nikolov
>From c9d651cfd532da6494dab03190c0a207cdf7289c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nfo...@redhat.com>
Date: Mon, 23 Jul 2018 17:38:26 +0200
Subject: [PATCH] api.c: always move all tasks of a process to a cgroup

---
 src/api.c | 40 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/api.c b/src/api.c
index 803ff35..a2cf981 100644
--- a/src/api.c
+++ b/src/api.c
@@ -3184,7 +3184,12 @@ int cgroup_change_cgroup_path(const char *dest, pid_t pid,
 				const char *const controllers[])
 {
 	int ret;
+	int nr;
 	struct cgroup cgroup;
+	DIR *dir;
+	struct dirent *task_dir = NULL;
+	char path[FILENAME_MAX];
+	pid_t tid;
 
 	if (!cgroup_initialized) {
 		cgroup_warn("Warning: libcgroup is not initialized\n");
@@ -3195,11 +3200,42 @@ int cgroup_change_cgroup_path(const char *dest, pid_t pid,
 	ret = cg_prepare_cgroup(&cgroup, pid, dest, controllers);
 	if (ret)
 		return ret;
-	/* Add task to cgroup */
+	/* Add process to cgroup */
 	ret = cgroup_attach_task_pid(&cgroup, pid);
-	if (ret)
+	if (ret) {
 		cgroup_warn("Warning: cgroup_attach_task_pid failed: %d\n",
 				ret);
+		goto finished;
+	}
+
+	/* Add all threads to cgroup */
+	snprintf(path, FILENAME_MAX, "/proc/%d/task/", pid);
+	dir = opendir(path);
+	if (!dir) {
+		last_errno = errno;
+		ret = ECGOTHER;
+		goto finished;
+	}
+
+	while ((task_dir = readdir(dir)) != NULL) {
+		nr = sscanf(task_dir->d_name, "%i", &tid);
+		if (nr < 1)
+			continue;
+
+		if (tid == pid)
+			continue;
+
+		ret = cgroup_attach_task_pid(&cgroup, tid);
+		if (ret) {
+			cgroup_warn("Warning: cgroup_attach_task_pid failed: %d\n",
+					ret);
+			break;
+		}
+	}
+
+	closedir(dir);
+
+finished:
 	cgroup_free_controllers(&cgroup);
 	return ret;
 }
-- 
2.17.1

Reply via email to