From 992807de55bd9b0e8cbb569a86bb84b75fe9482e Mon Sep 17 00:00:00 2001
From: Alexander V Vershilov <qnikst@gentoo.org>
Date: Sun, 30 Jun 2013 16:32:30 +0400
Subject: [PATCH] Put a service on into a top hierarchy of each cgroup

This change will fix unwanted cgroup inheriting from user cgroups,
and fixes issues with systemd cgroup tracking by logind.

However this fix can lead to incorrect work for some user cgroup
controllers - so more advanced solution, that coveres such cases
will be created later.

Thanks to Fabio Erculiani (lxnay) for testing and general idea.
---
 sh/rc-cgroup.sh.in | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index d96aa164..21f5f50d 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -72,6 +72,14 @@ cgroup_set_values()
 
 cgroup_set_limits()
 {
+    # relocate starting process to the top of the cgroup
+    # it prevents from unwanted inheriting of the user
+    # cgroups. But may lead to a problems where that inheriting
+    # is needed.
+	for d in /sys/fs/cgroup/* ; do
+		echo $$ > "${d}"/tasks
+	done
+
 	openrc_cgroup=/sys/fs/cgroup/openrc
 	if [ -d "$openrc_cgroup" ]; then
 		cgroup="$openrc_cgroup/$RC_SVCNAME"