librlimit: rlimit sandbox for any process
  • C 78.2%
  • Shell 14.4%
  • Makefile 7.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-02-23 07:03:21 -05:00
test test: freebsd: ignore output 2023-04-09 07:10:48 -04:00
.gitignore librlimit: LD_PRELOAD rlimit sandbox 2019-04-07 08:15:52 -04:00
librlimit.c librlimit: reformat, update copyright date 2026-02-20 08:01:26 -05:00
LICENSE doc: update copyright dates 2026-02-23 07:03:21 -05:00
Makefile librlimit: LD_PRELOAD rlimit sandbox 2019-04-07 08:15:52 -04:00
README.md doc: README: formatting 2026-02-22 09:15:12 -05:00

librlimit

librlimit: rlimit sandbox for any process

DESCRIPTION

librlimit sets up rlimit process restrictions for dynamically linked executables. The restrictions are enforced after the executable has loaded any shared libraries.

The shell ulimit or daemontools softlimit apply to the process lifetime from fork() to exec(). The process will typically need to perform operations like opening a file descriptor to linked libraries:

  • fork a subprocess
  • load shared libraries
  • nsswitch: read configuration files

For example:

  • ulimit
$ (ulimit -n 0; ls)
ls: error while loading shared libraries: libselinux.so.1: cannot open shared object file: Error 24
  • softlimit
$ softlimit -o 0 ls
ls: error while loading shared libraries: libselinux.so.1: cannot open shared object file: Error 24
  • librlimit
LD_PRELOAD=librlimit.so RLIMIT_NOFILE=0 ls
ls: cannot open directory '.': Too many open files

EXAMPLES

$ LD_PRELOAD=librlimit.so RLIMIT_FSIZE=0 yes > test
File size limit exceeded (core dumped)

$ LD_PRELOAD=librlimit.so RLIMIT_NPROC=0 sh -c "sleep 60 & sleep 60 & sleep 60 & sleep 60"
sh: 0: Cannot fork

$ LD_PRELOAD=librlimit.so RLIMIT_NOFILE=0 cat -n
abc
     1  abc

ENVIRONMENT VARIABLES

LIBRLIMIT_OPT
set options for the library behaviour (default: 1)
  • 0: no options enabled
  • 1: exit with status 111 if setting rlimit fails
  • 2: enable debug
  • 3: exit on failure and debug enabled

Supported resources are platform dependent. See setrlimit(3).

RLIMIT_AS
maximum size of process' virtual memory (address space)
RLIMIT_CORE
maximum size of a core file
RLIMIT_CPU
limit in seconds on CPU time
RLIMIT_DATA
maximum size of the process' data segment
RLIMIT_FSIZE
maximum file size in bytes
RLIMIT_LOCKS
limits the number of flock(2) locks and fcntl(2) leases
RLIMIT_MEMLOCK
maximum number of bytes available to be locked into memory
RLIMIT_MSGQUEUE
maximum of bytes allocated for POSIX message queues
RLIMIT_NICE
limits priority of process
RLIMIT_NOFILE
maximum number of file descriptors
RLIMIT_NPROC
maximum number of processes
RLIMIT_RSS
maximum number of bytes for a process resident set size
RLIMIT_RTPRIO
maximum real-time priority of process
RLIMIT_RTTIME
limit in microseconds for real-time scheduled CPU time
RLIMIT_SIGPENDING
maximum number of queued signals
RLIMIT_STACK
maximum size of process stack
RLIMIT_SBSIZE
maximum size of all socket buffers (FreeBSD)
RLIMIT_VMEM
virtual process size (incl. mmap) (equivalent to RLIMIT_AS) (FreeBSD)
RLIMIT_NPTS
pseudo-terminals (FreeBSD)
RLIMIT_SWAP
swap used (FreeBSD)
RLIMIT_KQUEUES
kqueues allocated (FreeBSD)
RLIMIT_UMTXP
process-shared umtx (FreeBSD)