SVN: rc-scripts/trunk/rc.d/init.d/functions

glen glen at pld-linux.org
Thu Nov 1 01:33:06 CET 2007


Author: glen
Date: Thu Nov  1 01:33:05 2007
New Revision: 8922

Modified:
   rc-scripts/trunk/rc.d/init.d/functions
Log:
- set ulimits with one awk call in daemon()

Modified: rc-scripts/trunk/rc.d/init.d/functions
==============================================================================
--- rc-scripts/trunk/rc.d/init.d/functions	(original)
+++ rc-scripts/trunk/rc.d/init.d/functions	Thu Nov  1 01:33:05 2007
@@ -466,17 +466,27 @@
 	return $exit_code
 }
 
+_daemon_set_ulimits() {
+	eval $(echo "${SERVICE_LIMITS:-$DEFAULT_SERVICE_LIMITS}" | awk -vksh="${KSH_VERSION:+1}" '
+		BEGIN {RS="[\n-]"} {
+			if ($1) {
+				if (ksh) {
+					if ($1 == "Su") $1 = "Sp";
+					if ($1 == "Hu") $1 = "Hp";
+					if ($1 == "u") $1 = "p";
+				}
+				printf("ulimit -%s %s; ", $1, $2);
+			}
+		}'
+	)
+}
+
 # A function to start a program (now it's useful on read-only filesystem too)
 daemon()
 {
-	typeset errors="" prog="" limits="" waitname="" waittime=""
+	typeset errors="" prog="" waitname="" waittime=""
 	typeset -i exit_code=0
 	[ -z "$DEFAULT_SERVICE_RUN_NICE_LEVEL" ] && DEFAULT_SERVICE_RUN_NICE_LEVEL=0
-	# "-u unlimited" (-p for ksh) to make sure daemons will be able to fork.
-	# "-c 0" to make sure it doesn't core dump anywhere; while this could mask
-	# problems with the daemon, it also closes some security problems.
-	# Users' limits are set via pam_limits.
-	[ -z "$DEFAULT_SERVICE_LIMITS" ] && DEFAULT_SERVICE_LIMITS="-u unlimited -c 0"
 	# Test syntax. Don't use -o instead || here - this will break ksh --misiek
 	while [ "$1" != "${1##-}" ] || [ "$1" != "${1##+}" ]; do
 		case $1 in
@@ -523,16 +533,7 @@
 		prog="$prog $*$end"
 	fi
 
-	if [ -n "$KSH_VERSION" ]; then
-		limits="$(echo "${SERVICE_LIMITS:-$DEFAULT_SERVICE_LIMITS}" | awk '/-Su/ {sub(/-Su/,"-Sp");} /-Hu/ {sub(/-Hu/,"-Hp");} /-u/ {sub(/-u/,"-p");} {print;}')"
-	elif [ -n "$ZSH_VERSION" ]; then
-		limits="${SERVICE_LIMITS:-$DEFAULT_SERVICE_LIMITS}"
-	elif [ -n "$BASH_VERSION" ]; then
-		limits="${SERVICE_LIMITS:-$DEFAULT_SERVICE_LIMITS}"
-#	elif [ -n "$($SH -c 'echo ${.sh.version}' 2>/dev/null)" ]; then
-	fi
-
-	[ -n "$limits" ] && eval $(echo "$limits" | awk 'BEGIN {RS="[\n-]";} !/^ *$/ { printf("ulimit -%s ;", $0); }')
+	_daemon_set_ulimits
 
 	[ -z "$DEFAULT_SERVICE_UMASK" ] && DEFAULT_SERVICE_UMASK=022
 


More information about the pld-cvs-commit mailing list