FreeBSD has a feature called login classes that allow the system administrator to:
-
Configure resource limits in
/etc/login.confthat will be applied to each new process executed under the respective login class. -
Set up aggregate resource limits for the collection of all processes running under a login class using
rctl.
Unfortunately, FreeBSD does not include a simple way to set the login class from a script or the command line.
The setloginclass program provided here is a simple command-line tool that
sets the login class, along with the corresponding resource limits and MAC label
from login.conf.
-
System administrators can create scripts to explicitly set the login class of a program being executed.
-
The
rcsubsystem can be modified to properly set both the login class and the MAC label of a daemon automatically started at boot time.
make && make installThis will create /usr/sbin/setloginclass. Note that this isn't installed in
/usr/local/sbin to allow you to modify /etc/rc.subr to properly set the
login class for daemons started prior to mounting /usr/local.
This program can only be run as root.
# Set the "human" login class and its resource limits for just this command.
setloginclass human /command/run/by/human
# Same as above but also set the MAC label.
setloginclass -m human /command/run/by/human-
I originally posted this program in this bug.
-
This program will not work in jails.
-
You cannot change the login class of a process if you're using
mac_bibaand the caller cannot usebiba/equal. (This is an undocumented feature ofmac_biba.) -
There is a bug in
libutilthat prevents the login class from being set if the same operation is also going to set the MAC label andbiba/equalis not allowed by that label. (See this bug for a patch.) -
Don't forget to run
cap_mkdbif you updatelogin.conf.