From 320f60ca40b3bd397d82b6968b7f432271c06c12 Mon Sep 17 00:00:00 2001 From: millert <> Date: Wed, 18 May 2005 13:44:35 +0000 Subject: [PATCH] o move sysctl and mixerctl parsing into a subroutine instead of a subshell o update resource limits if kern.maxproc or kern.maxfiles is changed --- src/etc/rc | 77 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/src/etc/rc b/src/etc/rc index b27ea88d..bd9a6ddd 100644 --- a/src/etc/rc +++ b/src/etc/rc @@ -1,4 +1,4 @@ -# $OpenBSD: rc,v 1.264 2005/04/09 14:15:18 deraadt Exp $ +# $OpenBSD: rc,v 1.265 2005/05/18 13:44:35 millert Exp $ # System startup script run by init on autoboot # or after single-user. @@ -22,6 +22,63 @@ stripcom() { } < $_file } +# Update resource limits when sysctl changes +# Usage: update_limit -X loginconf_name +update_limit() { + local _fl="$1" # ulimit flag + local _lc="$2" # login.conf name + local _new _suf + + for _suf in "" -cur -max; do + _new=`getcap -f /etc/login.conf -s ${_lc}${_suf} daemon 2>/dev/null` + if [ X"$_new" != X"" ]; then + if [ X"$_new" = X"infinity" ]; then + _new=unlimited + fi + case "$_suf" in + -cur) + ulimit -S $_fl $_new + ;; + -max) + ulimit -H $_fl $_new + ;; + *) + ulimit $_fl $_new + return + ;; + esac + fi + done +} + +sysctl_conf() { + # delete comments and blank lines + set -- `stripcom /etc/sysctl.conf` + while [ $# -ge 1 ] ; do + sysctl $1 + # update limits if needed + case $1 in + kern.maxproc=*) + update_limit -p maxproc + ;; + kern.maxfiles=*) + update_limit -n openfiles + ;; + esac + shift + done +} + +mixerctl_conf() +{ + # delete comments and blank lines + set -- `stripcom /etc/mixerctl.conf` + while [ $# -ge 1 ] ; do + mixerctl -q $1 > /dev/null 2>&1 + shift + done +} + # End subroutines stty status '^T' @@ -161,25 +218,11 @@ if [ "X${pf}" != X"NO" ]; then fi if [ -f /etc/sysctl.conf ]; then -( - # delete comments and blank lines - set -- `stripcom /etc/sysctl.conf` - while [ $# -ge 1 ] ; do - sysctl $1 - shift - done -) + sysctl_conf fi if [ -f /etc/mixerctl.conf ]; then -( - # delete comments and blank lines - set -- `stripcom /etc/mixerctl.conf` - while [ $# -ge 1 ] ; do - mixerctl -q $1 > /dev/null 2>&1 - shift - done -) + mixerctl_conf fi # set hostname, turn on network