Index: etc/rc.subr =================================================================== --- etc/rc.subr +++ etc/rc.subr @@ -755,6 +755,8 @@ # # ${name}_nice n Nice level to run ${command} at. # +# ${name}_oomprotect n Protect against OOM Killer. +# # ${name}_user n User to run ${command} as, using su(1) if not # using ${name}_chroot. # Requires /usr to be mounted. @@ -944,7 +946,8 @@ _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 @@ -1050,6 +1053,22 @@ if [ -n "$_prepend" ]; then _doit="$_prepend $_doit" fi + if [ -n "$_oomprotect" ]; then + if [ -r /usr/bin/protect ]; then + case $_oomprotect in + [Aa][Ll][Ll]) + echo "all" + _doit="protect -i ${command} ${rc_flags}" + ;; + [Yy][Ee][Ss]) + echo "yes" + pgrep ${command} + #_doit="${command} ${rc_flags}; pgrep ${command} | xargs protect -p" + pgrep ${command} + ;; + esac + fi + fi fi # Prepend default limits Index: usr.bin/protect/protect.1 =================================================================== --- usr.bin/protect/protect.1 +++ usr.bin/protect/protect.1 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 19, 2013 +.Dd February 03, 2016 .Dt PROTECT 1 .Os .Sh NAME @@ -53,6 +53,8 @@ Apply the operation to all current children of the specified processes. .It Fl i Apply the operation to all future children of the specified processes. +.It Fl s +Apply the operation to the specified processes. .It Fl g Ar pgrp Apply the operation to all processes in the specified process group. .It Fl p Ar pid Index: usr.bin/protect/protect.c =================================================================== --- usr.bin/protect/protect.c +++ usr.bin/protect/protect.c @@ -42,8 +42,8 @@ usage(void) { - fprintf(stderr, "usage: protect [-i] command\n"); - fprintf(stderr, " protect [-cdi] -g pgrp | -p pid\n"); + fprintf(stderr, "usage: protect [-i|-s] command\n"); + fprintf(stderr, " protect [-cdi|-cs] -g pgrp | -p pid\n"); exit(1); } @@ -78,7 +78,7 @@ id = getpid(); flags = PPROT_SET; descend = inherit = idset = false; - while ((ch = getopt(argc, argv, "cdig:p:")) != -1) + while ((ch = getopt(argc, argv, "cdisg:p:")) != -1) switch (ch) { case 'c': flags = PPROT_CLEAR; @@ -89,6 +89,8 @@ case 'i': inherit = true; break; + case 's': + break; case 'g': idtype = P_PGID; id = parse_id(optarg);