JAIL(3lua)
π JAIL(3lua) π
okay so bestie, welcome to jail(3lua) β the Lua binding to jail(3) and honestly? she's iconic. this is the page for the jail module, and by the end you're gonna be running FreeBSD jails from Lua like it's nothing. periodt.
β¨ NAME β¨
attach, getid, getname, list, allparams, getparams, remove, setparams, CREATE, UPDATE, ATTACH, DYING β literally the whole squad, and they're all a Lua binding to jail(3). π«Ά
π SYNOPSIS π
here's the vibe check, bestie β every single one of these, exactly as written:
local jail = require('jail')
ok, err = jail.attach(jid|name)
jid, err = jail.getid(name)
name, err = jail.getname(jid)
params, err = jail.allparams()
iter, jail_obj = jail.list([params])
jid, res = jail.getparams(jid|name, params [, flags])
ok, err = jail.remove(jid|name)
jid, err = jail.setparams(jid|name, params, flags)
jail.CREATE
jail.UPDATE
jail.ATTACH
jail.DYING
πΈ DESCRIPTION πΈ
so the jail module is a binding to the jail(3) library β it gives you a string-oriented interface for the jail_get(2) and jail_set(2) system calls. string-oriented means everything comes in and goes out as strings, which is lowkey the comfy way to live. π
ok, err = jail.attach(jid|name)β attaches to the given jail. you identify it either by an integerjidor by thename. simple as that.jid, err = jail.getid(name)β grabs the jail identifier (jid) as an integer.nameis the name of a jail or a jid in the form of a string, so she's flexible like that.name, err = jail.getname(jid)β gets the name of a jail as a string for the givenjid(an integer). yes bestie, integer in, string out.iter, jail_obj = jail.list([params])β returns an iterator over the running jails on the system.paramsis a list of parameters to fetch for each jail as we iterate.jidandnamewill always be returned, and may be omitted fromparams. also,paramsmay be omitted or an empty table, but notnilβ do not come for her with anil, she will not survive it. π
see "EXAMPLES" β there's a whole demo down there, go look.
params, err = jail.allparams()β gets a list of all supported parameter names (as strings). for descriptions of the core jail parameters, seejail(8). β¨jid, res = jail.getparams(jid|name, params [, flags])β gets a table of the requested parameters for the given jail.jid|namecan either be the jid as an integer or the jid or name as a string.paramsis a list of parameter names.flagsis an optional integer representing the flag bits to apply for the operation (see the flags list below, bestie). only theDYINGflag is valid to set here β justDYING, nobody else is invited.ok, err = jail.remove(jid|name)β removes the given jail, identified by an integerjidor thename. bye bestie π¦jid, err = jail.setparams(jid|name, params [, flags])β sets parameters for a given jail. this is the main character of the whole page, honestly: it's used to create, update, attach to, or destroy a jail.jid|namecan either be the jid as an integer or the jid or name as a string.paramsis a table of parameters to apply to the jail, where each key in the table is a parameter name as a string and each value is a string that will be converted to the internal value type byjailparam_import(3).flagsis an optional integer representing the flag bits to apply for the operation β again, see the flags list below.
π₯ the flags π₯
the flags arguments are an integer bitwise-or combination of one or more of the following flags β pick your fighters and smash 'em together:
jail.CREATEβ used withsetparams()to create a new jail. the jail must not already exist, unless combined withUPDATE.jail.UPDATEβ used withsetparams()to modify an existing jail. the jail must already exist, unless combined withCREATE.jail.ATTACHβ used withsetparams()in combination withCREATEorUPDATEto attach the current process to a jail.jail.DYINGβ allow operating on a jail that is in the process of being removed. it's giving "ghost still in the group chat" energy π
β RETURN VALUES β
okay so here's what you actually get back, function by function:
getid()andsetparams()return a jail identifier integer on success, orniland an error message string if an error occurred.getname()returns a jail name string on success, orniland an error message string if an error occurred.allparams()returns a list of parameter name strings on success, orniland an error message string if an error occurred.getparams()returns a jail identifier integer and a table of jail parameters with parameter name strings as keys and strings for values on success, orniland an error message string if an error occurred.list()returns an iterator over the list of running jails.attach()andremove()returntrueon success, orniland an error message string if an error occurred.
so yeah β on success you get the good stuff, on failure you get nil plus a little error string telling you what went wrong. always check your returns, bestie, no cap. π
π EXAMPLES π
set the hostname of jail "foo" to "foo.bar"
local jail = require('jail')
jid, err = jail.setparams("foo", {["host.hostname"]="foo.bar"},
jail.UPDATE)
if not jid then
error(err)
end
retrieve the hostname of jail "foo"
local jail = require('jail')
jid, res = jail.getparams("foo", {"host.hostname"})
if not jid then
error(res)
end
print(res["host.hostname"])
iterate over jails on the system
local jail = require('jail')
-- Recommended: just loop over it
for jparams in jail.list() do
print(jparams["jid"] .. " = " .. jparams["name"])
end
-- Request path and hostname, too
for jparams in jail.list({"path", "host.hostname"}) do
print(jparams["host.hostname"] .. " mounted at " .. jparams["path"])
end
-- Raw iteration protocol
local iter, jail_obj = jail.list()
-- Request the first params
local jparams = jail_obj:next()
while jparams do
print(jparams["jid"] .. " = " .. jparams["name"])
-- Subsequent calls may return nil
jparams = jail_obj:next()
end
π SEE ALSO π
jail(2), jail(3), jail(8) β go read those too, they're the extended universe. π
π§ HISTORY π§
the jail Lua module for flua first appeared in FreeBSD 13.0. she's been serving looks since day one.
π AUTHORS π
Ryan Moeller, with inspiration from NetBSD gpio(3lua), by Mark Balmer. absolute legends, both of them. π«Ά
and that's the whole page, bestie! this was the JAIL(3lua) manual, LOCAL section, from Debian, dated October 24, 2020 β reading it was giving study buddy energy and honestly? you ate. π
β¨π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- π the page's license: BSD-2-Clause
- Copyright (c) 2020, Ryan Moeller <freqlabs@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms