From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-731389-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	by finch.gentoo.org (Postfix) with ESMTP id 1F98813838B
	for <garchives@archives.gentoo.org>; Thu, 11 Sep 2014 19:06:39 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 6F605E08CE;
	Thu, 11 Sep 2014 19:06:36 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 1C16CE08CE
	for <gentoo-commits@lists.gentoo.org>; Thu, 11 Sep 2014 19:06:36 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 0B3A83401BC
	for <gentoo-commits@lists.gentoo.org>; Thu, 11 Sep 2014 19:06:35 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 9661153BA
	for <gentoo-commits@lists.gentoo.org>; Thu, 11 Sep 2014 19:06:33 +0000 (UTC)
From: "William Hubbs" <williamh@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" <williamh@gentoo.org>
Message-ID: <1410460018.50658449bd46f1a53b8eb11d34f6eefdd1ceba9c.williamh@OpenRC>
Subject: [gentoo-commits] proj/openrc:master commit in: sh/
X-VCS-Repository: proj/openrc
X-VCS-Files: sh/runscript.sh.in
X-VCS-Directories: sh/
X-VCS-Committer: williamh
X-VCS-Committer-Name: William Hubbs
X-VCS-Revision: 50658449bd46f1a53b8eb11d34f6eefdd1ceba9c
X-VCS-Branch: master
Date: Thu, 11 Sep 2014 19:06:33 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: b3ecd990-59fe-49b0-9cc3-fb726b7c4b38
X-Archives-Hash: 39d75c38e6002cacb6a20bc1a3969df9

commit:     50658449bd46f1a53b8eb11d34f6eefdd1ceba9c
Author:     Roy Marples <roy <AT> marples <DOT> name>
AuthorDate: Thu Sep 11 18:26:58 2014 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Thu Sep 11 18:26:58 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=50658449

Use exception-based approach for cgroup/ulimit setup

Note from William Hubbs:
I spoke with Roy about this, and he pointed out that user-defined
functions may need the limits applied, so it is better to go with a
method that uses exceptions to determine which functions apply the
limits.

X-Gentoo-Bug: 522408
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=522408

---
 sh/runscript.sh.in | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index d4c7c60..b89c460 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -209,19 +209,29 @@ unset _conf_d
 # Load any system overrides
 sourcex -e "@SYSCONFDIR@/rc.conf"
 
-# Apply any ulimit defined
-[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}
-
-# Apply cgroups settings if defined
-if [ "$1" = "start" ] ; then
-	if [ "$(command -v cgroup_add_service)" = "cgroup_add_service" ]; then
-		cgroup_add_service /sys/fs/cgroup/openrc
-		cgroup_add_service /sys/fs/cgroup/systemd/system
+for _cmd; do
+	if [ "$_cmd" != status -a "$_cmd" != describe ]; then
+		# Apply any ulimit defined
+		[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && \
+			ulimit ${rc_ulimit:-$RC_ULIMIT}
+		# Apply cgroups settings if defined
+		if [ "$(command -v cgroup_add_service)" = \
+		    "cgroup_add_service" ]
+		then
+			if [ -d /sys/fs/cgroup -a ! -w /sys/fs/cgroup ]; then
+				eerror "No permission to apply cgroup settings"
+				break
+			fi
+			cgroup_add_service /sys/fs/cgroup/openrc
+			cgroup_add_service /sys/fs/cgroup/systemd/system
+		fi
+		[ "$(command -v cgroup_set_limits)" = \
+		    "cgroup_set_limits" ] && \
+		    cgroup_set_limits
+		break
 	fi
-	[ "$(command -v cgroup_set_limits)" = "cgroup_set_limits" ] && \
-		cgroup_set_limits
-fi
-
+done
+ 
 # Load our script
 sourcex "$RC_SERVICE"