aristanetworks / bst

A one-stop shop for process isolation
MIT License
99 stars 9 forks source link

cli: add new "--limit-<XXX>" options #21

Closed wwade closed 4 years ago

wwade commented 4 years ago

To give the user more control over the bst process, add three new options for runing setrlimit before exec.

--limit-core: RLIMIT_CORE
--limit-nofile: RLIMIT_NOFILE
--limit-nproc: RLIMIT_NPROC

Each option requires an argument which is parsed as a colon-separated tuple of hard, soft resource limits. Each of hard and soft limits are optional, and when one is not specified, it will use the current value. The only exception is for the special value ":" which will use the current hard limit, and set the soft limit to the hard limit value.

--limit-nofile=100 => setrlimit(RLIMIT_NOFILE, (100, 100))
--limit-nofile=100:50 => setrlimit(RLIMIT_NOFILE, (100, 50))
--limit-nofile=100: => setrlimit(RLIMIT_NOFILE, (100, cur))
--limit-nofile=:100 => setrlimit(RLIMIT_NOFILE, (cur, 100))
--limit-nofile=: => setrlimit(RLIMIT_NOFILE, (cur, hard))

Added test cases to bst.t and also added a unit test for the parsing code.

Usage strings:

--limit-core (<value>)|(<hard>:<soft>)
                        Set RLIMIT_CORE to the provided value(s).
--limit-nofile (<value>)|(<hard>:<soft>)
                        Set RLIMIT_NOFILE to the provided value(s).
--limit-nproc (<value>)|(<hard>:<soft>)
                        Set RLIMIT_NPROC to the provided value(s).
wwade commented 4 years ago

Looks good, with a few comments. There are two things I'd also like you to add:

  • Could you add an entry in bst.1.scd documenting the new --limit- flags? Will do.

  • I'd like the rlimit implementation to be complete -- let's add support for all RLIMIT_* values. Prefer to do that in a follow up of some kind.