diff options
author | araujo <araujo@FreeBSD.org> | 2016-02-24 01:32:12 +0000 |
---|---|---|
committer | araujo <araujo@FreeBSD.org> | 2016-02-24 01:32:12 +0000 |
commit | bd6a91854eae451ea33663192a4183e0e2b8d2dd (patch) | |
tree | 7283f29397f0b9e2ec643a5b81c186aee1b19d71 /etc/rc.subr | |
parent | c2197759a2059fe92bc16e6763e6b3a0c7e4e5c4 (diff) | |
download | FreeBSD-src-bd6a91854eae451ea33663192a4183e0e2b8d2dd.zip FreeBSD-src-bd6a91854eae451ea33663192a4183e0e2b8d2dd.tar.gz |
- Add a global option where we can protect processes when swap space
is exhausted.
How to use:
Basically we need to add on rc.conf an another option like:
If we want to protect only the main processes.
syslogd_oomprotect="YES"
If we want to protect all future children of the specified processes.
syslogd_oomprotect="ALL"
PR: 204741 (based on)
Submitted by: eugen@grosbein.net
Reviewed by: jhb, allanjude, rpokala and bapt
MFC after: 4 weeks
Relnotes: Yes
Sponsored by: gandi.net
Differential Revision: https://reviews.freebsd.org/D5176
Diffstat (limited to 'etc/rc.subr')
-rw-r--r-- | etc/rc.subr | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/etc/rc.subr b/etc/rc.subr index a6de452..cdec9a2 100644 --- a/etc/rc.subr +++ b/etc/rc.subr @@ -45,6 +45,7 @@ _rc_subr_loaded="YES" SYSCTL="/sbin/sysctl" SYSCTL_N="${SYSCTL} -n" SYSCTL_W="${SYSCTL}" +PROTECT="/usr/bin/protect" ID="/usr/bin/id" IDCMD="if [ -x $ID ]; then $ID -un; fi" PS="/bin/ps -ww" @@ -755,6 +756,8 @@ check_startmsgs() # # ${name}_nice n Nice level to run ${command} at. # +# ${name}_oomprotect n Don't kill ${command} when swap space is exhausted. +# # ${name}_user n User to run ${command} as, using su(1) if not # using ${name}_chroot. # Requires /usr to be mounted. @@ -944,7 +947,8 @@ run_rc_command() _nice=\$${name}_nice _user=\$${name}_user \ _group=\$${name}_group _groups=\$${name}_groups \ _fib=\$${name}_fib _env=\$${name}_env \ - _prepend=\$${name}_prepend _login_class=\${${name}_login_class:-daemon} + _prepend=\$${name}_prepend _login_class=\${${name}_login_class:-daemon} \ + _oomprotect=\$${name}_oomprotect if [ -n "$_user" ]; then # unset $_user if running as that user if [ "$_user" = "$(eval $IDCMD)" ]; then @@ -1182,6 +1186,26 @@ $command $rc_flags $command_args" ;; esac + + # Apply protect(1) to the PID if ${name}_oomprotect is set. + case "$rc_arg" in + start) + if [ -n "$_oomprotect" ]; then + if [ -f "${PROTECT}" ]; then + pid=$(check_process $command) + case $_oomprotect in + [Aa][Ll][Ll]) + ${PROTECT} -i -p ${pid} + ;; + [Yy][Ee][Ss]) + ${PROTECT} -p ${pid} + ;; + esac + fi + fi + ;; + esac + return $_return done |