JAIL(3)
π JAIL(3) β create and manage system jails π
okay bestie, welcome to the Library Functions Manual for JAIL(3) β we're doing jails, and yes, it's giving main-character system-call energy π«Ά
πΈ NAME πΈ
jail_getid, jail_getname, jail_setv, jail_getv, jailparam_all, jailparam_init, jailparam_import, jailparam_import_raw, jailparam_set, jailparam_get, jailparam_export, and jailparam_free β the whole squad π
. Their job? create and manage system jails. no cap.
π«Ά LIBRARY π«Ά
Jail Library (libjail, -ljail). Link it, bestie.
β¨ SYNOPSIS β¨
#include <sys/param.h>
#include <sys/jail.h>
#include <jail.h>
extern char jail_errmsg[];
int
jail_getid(const char *name);
char *
jail_getname(int jid);
int
jail_setv(int flags, ...);
int
jail_getv(int flags, ...);
int
jailparam_all(struct jailparam **jpp);
int
jailparam_init(struct jailparam *jp, const char *name);
int
jailparam_import(struct jailparam *jp, const char *value);
int
jailparam_import_raw(struct jailparam *jp, void *value,
size_t valuelen);
int
jailparam_set(struct jailparam *jp, unsigned njp, int flags);
int
jailparam_get(struct jailparam *jp, unsigned njp, int flags);
char *
jailparam_export(struct jailparam *jp);
void
jailparam_free(struct jailparam *jp, unsigned njp);
π¦ DESCRIPTION π¦
The jail library is literally an interface to the jail_set(2) and jail_get(2) system calls, plus the security.jail.param MIB entries. It simplifies converting prison parameters between internal and string formats, so you can set and query prisons without knowing the parameter formats. iconic.
jail_getid()β returns the JID of the jail identified by name, or-1if the jail does not exist.jail_getname()β returns the name of the jail identified by jid, orNULLif the jail does not exist.jail_setv()β takes a null-terminated list of name and value strings, and passes it tojail_set(2).jail_getv()β takes a null-terminated list of name and value strings, and passes it tojail_get(2). It is the caller's responsibility to ensure that the value strings point to buffers large enough to hold the string representation of the returned parameters. yes, that means size your buffers, bestie πjailparam_all()β sets jpp to a list of all known jail parameters, and returns the number of parameters. The list should later be freed withjailparam_free()andfree(3).jailparam_init()β clears a parameter record and copies the name to it. After use, it should be freed withjailparam_free().jailparam_import()β adds a value to a parameter record, converting it from a string to its native form.jailparam_import_raw()β adds a value without performing any conversion.jailparam_set()β passes a list of parameters tojail_set(2). The parameters are assumed to have been created withjailparam_init()andjailparam_import().jailparam_get()β passes a list of parameters tojail_get(2). The parameters are assumed to have been created withjailparam_init()orjailparam_list(), with one parameter (the key) having been given a value withjailparam_import().jailparam_export()β returns the string equivalent of a parameter value. The returned string should be freed after use.jailparam_free()β frees the stored names and values in a parameter list. If the list itself came fromjailparam_all(), it should be freed as well.
π RETURN VALUES π
jail_getid(),jail_setv(),jail_getv(),jailparam_set(), andjailparam_get()return a JID on success, or-1on error.jail_getname()andjailparam_export()return a dynamically allocated string on success, orNULLon error.jailparam_all()returns the number of parameters on success, or-1on error.jailparam_init(),jailparam_import(), andjailparam_import_raw()return0on success, or-1on error.
Whenever an error is returned, errno is set, and the global string jail_errmsg contains a description of the error, possibly from jail_set(2) or jail_get(2). π«Ά
π EXAMPLES π
Set the hostname of jail βfooβ to βfoo.barβ:
jail_setv(JAIL_UPDATE, "name", "foo", "host.hostname", "foo.bar",
NULL);
OR:
struct jailparam params[2];
jailparam_init(¶ms[0], "name");
jailparam_import(¶ms[0], "foo");
jailparam_init(¶ms[1], "host.hostname");
jailparam_import(¶ms[1], "foo.bar");
jailparam_set(params, 2, JAIL_UPDATE);
jailparam_free(params, 2);
Retrieve the hostname of jail βfooβ:
char hostname[MAXHOSTNAMELEN];
jail_getv(0, "name", "foo", "host.hostname", hostname, NULL);
OR:
struct jailparam params[2];
jailparam_init(¶ms[0], "name");
jailparam_import(¶ms[0], "foo");
jailparam_init(¶ms[1], "host.hostname");
jailparam_get(params, 2, 0);
hostname = jailparam_export(¶ms[1]);
jailparam_free(params, 2);
...
free(hostname);
π ERRORS π
The jail functions may return errors from jail_set(2), jail_get(2), malloc(3) or sysctl(3). In addition, the following errors are possible:
[EINVAL]β A parameter value cannot be converted from the passed string to its internal form.[ENOENT]β The named parameter does not exist.[ENOENT]β A parameter is of an unknown type.
π SEE ALSO π
jail(2), sysctl(3), jail(3lua), jail(8) β go read the friends too, bestie π
π¦ HISTORY π¦
The jail library first appeared in FreeBSD 8.0. periodt.
π AUTHORS π
James Gritton
xoxo, this edition is from Debian, dated August 31, 2010, and it's the JAIL(3) page β mwah π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2009 James Gritton
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms