#[repr(C)]pub struct lxc_container {Show 50 fields
pub error_string: *mut c_char,
pub error_num: c_int,
pub daemonize: bool,
pub config_path: *mut c_char,
pub is_defined: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
pub state: unsafe extern "C" fn(c: *mut lxc_container) -> *const c_char,
pub is_running: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
pub freeze: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
pub unfeeze: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
pub init_pid: unsafe extern "C" fn(c: *mut lxc_container) -> c_uint,
pub load_config: unsafe extern "C" fn(c: *mut lxc_container, alt_file: *const c_char) -> bool,
pub start: unsafe extern "C" fn(c: *mut lxc_container, useinit: c_int, argv: *const *mut c_char),
pub start1: unsafe extern "C" fn(c: *mut lxc_container, useinit: c_int, ...) -> bool,
pub stop: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
pub want_daemonize: unsafe extern "C" fn(c: *mut lxc_container, state: bool) -> bool,
pub want_close_all_fds: unsafe extern "C" fn(c: *mut lxc_container, state: bool) -> bool,
pub config_file_name: unsafe extern "C" fn(c: *mut lxc_container) -> *mut c_char,
pub wait: unsafe extern "C" fn(c: *mut lxc_container, state: *const c_char, timeout: c_int) -> bool,
pub set_config_item: unsafe extern "C" fn(c: *mut lxc_container, key: *const c_char, value: *const c_char) -> bool,
pub destroy: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
pub save_config: unsafe extern "C" fn(c: *mut lxc_container, alt_file: *const c_char) -> bool,
pub create: unsafe extern "C" fn(c: *mut lxc_container, t: *const c_char, bdevtype: *const c_char, specs: *mut bdev_specs, flags: c_int, argv: *const *mut c_char) -> bool,
pub createl: unsafe extern "C" fn(c: *mut lxc_container, t: *const c_char, bdevtype: *const c_char, specs: *mut bdev_specs, flags: c_int, ...) -> bool,
pub rename: unsafe extern "C" fn(c: *mut lxc_container, newname: *const c_char) -> bool,
pub reboot: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
pub shutdown: unsafe extern "C" fn(c: *mut lxc_container, timeout: c_int) -> bool,
pub clear_config: unsafe extern "C" fn(c: *mut lxc_container) -> c_void,
pub clear_config_item: unsafe extern "C" fn(c: *mut lxc_container, key: *const c_char) -> bool,
pub get_config_item: unsafe extern "C" fn(c: *mut lxc_container, key: *const c_char, retv: *mut c_char, inlen: c_int) -> c_int,
pub get_running_config_item: unsafe extern "C" fn(c: *mut lxc_container, key: *const c_char) -> *mut c_char,
pub get_keys: unsafe extern "C" fn(c: *mut lxc_container, key: *const c_char, retv: *mut c_char, inlen: c_int) -> c_int,
pub get_interfaces: unsafe extern "C" fn(c: *mut lxc_container) -> *mut *mut c_char,
pub get_ips: unsafe extern "C" fn(c: *mut lxc_container, interface: *const c_char, family: *const c_char, scope: c_int) -> *mut *mut c_char,
pub get_cgroup_item: unsafe extern "C" fn(c: *mut lxc_container, subsys: *const c_char, retv: *mut c_char, inlen: c_int) -> c_int,
pub set_cgroup_item: unsafe extern "C" fn(c: *mut lxc_container, subsys: *const c_char, value: *const c_char) -> bool,
pub get_config_path: unsafe extern "C" fn(c: *mut lxc_container) -> *const c_char,
pub set_config_path: unsafe extern "C" fn(c: *mut lxc_container, path: *const c_char) -> bool,
pub clone: unsafe extern "C" fn(c: *mut lxc_container, newname: *const c_char, lxcpath: *const c_char, flags: c_int, bdevtype: *const c_char, bdevdata: *const c_char, newsize: u64, hookargs: *mut *mut c_char) -> *mut lxc_container,
pub console_getfd: unsafe extern "C" fn(c: *mut lxc_container, ttynum: *mut c_int, masterfd: *mut c_int) -> c_int,
pub console: unsafe extern "C" fn(c: *mut lxc_container, ttynum: c_int, stdinfd: c_int, stdoutfd: c_int, stderrfd: c_int, escape: c_int) -> c_int,
pub attach: unsafe extern "C" fn(c: *mut lxc_container, exec_function: lxc_attach_exec_t, exec_payload: *mut c_void, options: lxc_attach_options_t, attached_process: c_uint) -> c_int,
pub attach_run_wait: unsafe extern "C" fn(c: *mut lxc_container, options: lxc_attach_options_t, program: *const c_char, argv: *const *const c_char) -> c_int,
pub attach_run_wait1: unsafe extern "C" fn(c: *mut lxc_container, options: lxc_attach_options_t, program: *const c_char, ...) -> c_int,
pub snapshot: unsafe extern "C" fn(c: *mut lxc_container, commentfile: *const c_char) -> c_int,
pub snapshot_list: unsafe extern "C" fn(c: *mut lxc_container, snapshots: *mut *mut lxc_snapshot) -> c_int,
pub snapshot_restore: unsafe extern "C" fn(c: *mut lxc_container, snapname: *const c_char, newname: *const c_char) -> bool,
pub snapshot_destroy: unsafe extern "C" fn(c: *mut lxc_container, snapname: *const c_char) -> bool,
pub may_control: unsafe extern "C" fn(c: *mut lxc_container) -> bool,
pub add_device_node: unsafe extern "C" fn(c: *mut lxc_container, src_path: *const c_char, dest_path: *const c_char) -> bool,
pub remove_device_node: unsafe extern "C" fn(c: *mut lxc_container, src_path: *const c_char, dest_path: *const c_char) -> bool,
/* private fields */
}Expand description
An LXC container.
version: 1.0.0
Fields§
§error_string: *mut c_charHuman-readable string representing last error
version: 1.0.0
error_num: c_intLast error number
version: 1.0.0
daemonize: boolWhether container wishes to be daemonized
version: 1.0.0
config_path: *mut c_charFull path to configuration file
version: 1.0.0
is_defined: unsafe extern "C" fn(c: *mut lxc_container) -> boolDetermine if /var/lib/lxc/$name/config exists.
Parameters
c Container.
Returns
true if container is defined, else false.
version: 1.0.0
state: unsafe extern "C" fn(c: *mut lxc_container) -> *const c_charDetermine state of container.
Parameters
c Container.
Returns
Static upper-case string representing state of container.
note: Returned string must not be freed.
version: 1.0.0
is_running: unsafe extern "C" fn(c: *mut lxc_container) -> boolDetermine if container is running.
Parameters
c Container.
Returns
true on success, else false.
version: 1.0.0
freeze: unsafe extern "C" fn(c: *mut lxc_container) -> boolFreeze running container.
Parameters
§c Container.
Returns
true on success, else false.
version: 1.0.0
unfeeze: unsafe extern "C" fn(c: *mut lxc_container) -> boolThaw a frozen container.
Parameters
c Container.
Returns
true on success, else false.
version: 1.0.0
init_pid: unsafe extern "C" fn(c: *mut lxc_container) -> c_uintDetermine process ID of the containers init process.
Parameters
c Container.
Returns
pid of init process as seen from outside the container.
version: 1.0.0
load_config: unsafe extern "C" fn(c: *mut lxc_container, alt_file: *const c_char) -> boolLoad the specified configuration for the container.
Parameters
c Container.
alt_file Full path to alternate configuration file, or
NULL to use the default configuration file.
Returns
true on success, else false.
version: 1.0.0
start: unsafe extern "C" fn(c: *mut lxc_container, useinit: c_int, argv: *const *mut c_char)Start the container.
Parameters
c Container.
useinit Use lxcinit rather than /sbin/init.
argv Array of arguments to pass to init.
Returns
true on success, else false.
version: 1.0.0
start1: unsafe extern "C" fn(c: *mut lxc_container, useinit: c_int, ...) -> boolStart the container (list variant).
Parameters
c Container.
useinit Use lxcinit rather than /sbin/init.
… Command-line to pass to init (must end in NULL).
Returns
true on success, else false.
note: Identical to start except that that the init arguments are specified via a list rather than an array of pointers.
version: 1.0.0
stop: unsafe extern "C" fn(c: *mut lxc_container) -> boolStop the container.
Parameters
c Container.
Returns
true on success, else false.
version: 1.0.0
want_daemonize: unsafe extern "C" fn(c: *mut lxc_container, state: bool) -> boolDetermine if the container wants to run disconnected from the terminal.
Parameters
c Container.
state Value for the daemonize bit (0 or 1).
Returns
true if container wants to be daemonised, else false.
version: 1.0.0
want_close_all_fds: unsafe extern "C" fn(c: *mut lxc_container, state: bool) -> boolDetermine whether container wishes all file descriptors to be closed on startup.
Parameters
c Container.
state Value for the close_all_fds bit (0 or 1).
Returns
true if container wants all file descriptors closed,
else false.
version: 1.0.0
config_file_name: unsafe extern "C" fn(c: *mut lxc_container) -> *mut c_charReturn current config file name.
Parameters
c Container.
Returns
config file name, or NULL on error.
note: The result is allocated, so the caller must free the result.
version: 1.0.0
wait: unsafe extern "C" fn(c: *mut lxc_container, state: *const c_char, timeout: c_int) -> boolWait for container to reach a particular state.
Parameters
c Container.
state State to wait for.
timeout Timeout in seconds.
Returns
true if state reached within timeout, else false.
note: A timeout of -1 means wait forever. A timeout
of 0 means do not wait.
version: 1.0.0
set_config_item: unsafe extern "C" fn(c: *mut lxc_container, key: *const c_char, value: *const c_char) -> boolSet a key/value configuration option.
Parameters
c Container.
key Name of option to set.
value Value of name to set.
Returns
true on success, else false.
version: 1.0.0
destroy: unsafe extern "C" fn(c: *mut lxc_container) -> boolDelete the container.
Parameters
c Container.
Returns
true on success, else false.
note: Container must be stopped and have no dependent snapshots.
version: 1.0.0
save_config: unsafe extern "C" fn(c: *mut lxc_container, alt_file: *const c_char) -> boolSave configuaration to a file.
Parameters
c Container.
alt_file Full path to file to save configuration in.
Returns
true on success, else false.
version: 1.0.0
create: unsafe extern "C" fn(c: *mut lxc_container, t: *const c_char, bdevtype: *const c_char, specs: *mut bdev_specs, flags: c_int, argv: *const *mut c_char) -> boolCreate a container.
Parameters
c Container (with lxcpath, name and a starting configuration set).
t Template to execute to instantiate the root filesystem and adjust the configuration.
bdevtype Backing store type to use (if NULL, dir will be used).
specs Additional parameters for the backing store (for example LVM volume group to use).
flags LXC_CREATE_* options (currently only
LXC_CREATE_QUIET is supported).
argv Arguments to pass to the template, terminated by NULL
(if no arguments are required, just pass NULL).
Returns
true on success, else false.
version: 1.0.0
createl: unsafe extern "C" fn(c: *mut lxc_container, t: *const c_char, bdevtype: *const c_char, specs: *mut bdev_specs, flags: c_int, ...) -> boolCreate a container (list variant).
Parameters
c Container (with lxcpath, name and a starting configuration set).
t Template to execute to instantiate the root filesystem and adjust the configuration.
bdevtype Backing store type to use (if NULL, dir will be used).
specs Additional parameters for the backing store (for example LVM volume group to use).
flags LXC_CREATE_* options (currently only
LXC_CREATE_QUIET is supported).
… Command-line to pass to init (must end in NULL).
Returns
true on success, else false.
note: Identical to create except that the template arguments are specified as a list rather than an array of pointers.
version: 1.0.0
rename: unsafe extern "C" fn(c: *mut lxc_container, newname: *const c_char) -> boolRename a container
Parameters
c Container.
newname New name to be used for the container.
Returns
true on success, else false.
version: 1.0.0
reboot: unsafe extern "C" fn(c: *mut lxc_container) -> boolRequest the container reboot by sending it SIGINT.
Parameters
c Container.
Returns
true if reboot request successful, else false.
version: 1.0.0
shutdown: unsafe extern "C" fn(c: *mut lxc_container, timeout: c_int) -> boolRequest the container shutdown by sending it SIGPWR.
Parameters
c Container.
timeout Seconds to wait before returning false. (-1 to wait forever, 0 to avoid waiting).
Returns
true if the container was shutdown successfully, else false.
version: 1.0.0
clear_config: unsafe extern "C" fn(c: *mut lxc_container) -> c_voidCompletely clear the containers in-memory configuration.
Parameters
c Container.
version: 1.0.0
clear_config_item: unsafe extern "C" fn(c: *mut lxc_container, key: *const c_char) -> boolClear a configuration item.
Parameters
c Container.
key Name of option to clear.
Returns
true on success, else false.
note: Analog of set_config_item.
version: 1.0.0
get_config_item: unsafe extern "C" fn(c: *mut lxc_container, key: *const c_char, retv: *mut c_char, inlen: c_int) -> c_intRetrieve the value of a config item.
Parameters
c Container.
key Name of option to get.
retv out Caller-allocated buffer to write value of key into (or
NULL to determine length of value).
inlen Length of retv (may be zero).
Returns
Length of config items value, or < 0 on error.
note: The caller can (and should) determine how large a buffer to
allocate for retv by initially passing its value as NULL and
considering the return value. This function can then be called again
passing a newly-allocated suitably-sized buffer.
note: If retv is NULL, inlen is ignored.
note: If inlen is smaller than required, the value written to
retv will be truncated.
version: 1.0.0
get_running_config_item: unsafe extern "C" fn(c: *mut lxc_container, key: *const c_char) -> *mut c_charRetrieve the value of a config item from running container.
Parameters
c Container.
key Name of option to get.
Returns
the item or NULL on error.
note: Returned string must be freed by the caller.
version: 1.0.0
get_keys: unsafe extern "C" fn(c: *mut lxc_container, key: *const c_char, retv: *mut c_char, inlen: c_int) -> c_intRetrieve a list of config item keys given a key prefix
Parameters
c Container.
key Name of option to get.
retv out Caller-allocated buffer to write list of keys to (or
NULL to determine overall length of keys list).
inlen Length of retv (may be zero).
Returns
Length of keys list, or < 0 on error.
note: The list values written to retv are separated by a newline
character (‘\n’).
note: The caller can (and should) determine how large a buffer to
allocate for retv by initially passing its value as NULL and
considering the return value. This function can then be called again
passing a newly-allocated suitably-sized buffer.
note: If retv is NULL, inlen is ignored.
note: If inlen is smaller than required, the value written to
retv will be truncated.
version: 1.0.0
get_interfaces: unsafe extern "C" fn(c: *mut lxc_container) -> *mut *mut c_charObtain a list of network interfaces.
Parameters
c Container.
Returns
Newly-allocated array of network interfaces, or NULL on error.
note: The returned array is allocated, so the caller must free it.
note: The returned array is terminated with a NULL entry.
version: 1.0.0
get_ips: unsafe extern "C" fn(c: *mut lxc_container, interface: *const c_char, family: *const c_char, scope: c_int) -> *mut *mut c_charDetermine the list of container IP addresses.
Parameters
c Container.
interface Network interface name to consider.
family Network family (for example “inet”, “inet6”).
scope IPv6 scope id (ignored if family is not “inet6”).
Returns
Newly-allocated array of network interfaces, or NULL on error.
note: The returned array is allocated, so the caller must free it.
note: The returned array is terminated with a NULL entry.
version: 1.0.0
get_cgroup_item: unsafe extern "C" fn(c: *mut lxc_container, subsys: *const c_char, retv: *mut c_char, inlen: c_int) -> c_intRetrieve the specified cgroup subsystem value for the container.
Parameters
c Container.
subsys cgroup subsystem to retrieve.
retv out Caller-allocated buffer to write value of subsys into
(or NULL to determine length of value).
inlen length of retv (may be zero).
Returns
Length of subsys value, or < 0 on error.
note: If retv is NULL, inlen is ignored.
note: If inlen is smaller than required, the value written to
retv will be truncated.
version: 1.0.0
set_cgroup_item: unsafe extern "C" fn(c: *mut lxc_container, subsys: *const c_char, value: *const c_char) -> boolSet the specified cgroup subsystem value for the container.
Parameters
c Container.
subsys cgroup subsystem to consider.
value Value to set for subsys.
Returns
true on success, else false.
version: 1.0.0
get_config_path: unsafe extern "C" fn(c: *mut lxc_container) -> *const c_charDetermine full path to the containers configuration file.
Each container can have a custom configuration path. However
by default it will be set to either the LXCPATH configure
variable, or the lxcpath value in the LXC_GLOBAL_CONF configuration
file (i.e. /etc/lxc/lxc.conf).
The value for a specific container can be changed using
set_config_path. There is no other way
to specify this in general at the moment.
Parameters
c Container.
Returns
Static string representing full path to configuration file.
note: Returned string must not be freed.
version: 1.0.0
set_config_path: unsafe extern "C" fn(c: *mut lxc_container, path: *const c_char) -> boolSet the full path to the containers configuration file.
Parameters
c Container.
path Full path to configuration file.
Returns
true on success, else false.
version: 1.0.0
clone: unsafe extern "C" fn(c: *mut lxc_container, newname: *const c_char, lxcpath: *const c_char, flags: c_int, bdevtype: *const c_char, bdevdata: *const c_char, newsize: u64, hookargs: *mut *mut c_char) -> *mut lxc_containerCopy a stopped container.
Parameters
c Original container.
newname New name for the container. If NULL, the same name is
used and a new lxcpath MUST be specified.
lxcpath lxcpath in which to create the new container. If NULL,
the original container’s lxcpath will be used.
flags Additional LXC_CLONE* flags to change the cloning behaviour:
bdevtype Optionally force the cloned bdevtype to a specified plugin. By default the original is used (subject to snapshot requirements).
bdevdata Information about how to create the new storage (i.e. fstype and fsdata).
newsize In case of a block device backing store, an optional size.
If 0, the original backing store’s size will be used if possible. Note
this only applies to the rootfs. For any other filesystems, the original
size will be duplicated.
hookargs Additional arguments to pass to the clone hook script.
Returns
Newly-allocated copy of container c, or NULL on error.
note: If devtype was not specified, and flags contains
LXC_CLONE_SNAPSHOT then use the
native bdevtype if possible, else use an overlayfs.
version: 1.0.0
console_getfd: unsafe extern "C" fn(c: *mut lxc_container, ttynum: *mut c_int, masterfd: *mut c_int) -> c_intAllocate a console tty for the container.
Parameters
c Container.
ttynum in,out Terminal number to attempt to allocate, or -1 to
allocate the first available tty.
masterfd out File descriptor refering to the master side of the pty.
Returns
tty file descriptor number on success, or -1 on failure.
note: On successful return, ttynum will contain the tty number
that was allocated.
note: The returned file descriptor is used to keep the tty allocated. The caller should call close(2) on the returned file descriptor when no longer required so that it may be allocated by another caller.
version: 1.0.0
console: unsafe extern "C" fn(c: *mut lxc_container, ttynum: c_int, stdinfd: c_int, stdoutfd: c_int, stderrfd: c_int, escape: c_int) -> c_intAllocate and run a console tty.
Parameters
c Container.
ttynum Terminal number to attempt to allocate, -1 to
allocate the first available tty or 0 to allocate the
console.
stdinfd File descriptor to read input from.
stdoutfd File descriptor to write output to.
stderrfd File descriptor to write error output to.
escape The escape character (1 == ‘a’, 2 == ‘b’, …).
Returns
0 on success, -1 on failure.
note: This function will not return until the console has been exited by the user.
version: 1.0.0
attach: unsafe extern "C" fn(c: *mut lxc_container, exec_function: lxc_attach_exec_t, exec_payload: *mut c_void, options: lxc_attach_options_t, attached_process: c_uint) -> c_intCreate a sub-process attached to a container and run a function inside it.
Parameters
c Container.
exec_function Function to run.
exec_payload Data to pass to exec_function.
options See lxc_attach_options_t.
attached_process out Process ID of process running inside
container c that is running exec_function.
Returns
0 on success, -1 on error.
version: 1.0.0
attach_run_wait: unsafe extern "C" fn(c: *mut lxc_container, options: lxc_attach_options_t, program: *const c_char, argv: *const *const c_char) -> c_intRun a program inside a container and wait for it to exit.
Parameters
c Container.
options See lxc_attach_options_t.
program Full path inside container of program to run.
argv Array of arguments to pass to program.
Returns
waitpid(2) status of exited process that ran program, or -1 on
error.
version: 1.0.0
attach_run_wait1: unsafe extern "C" fn(c: *mut lxc_container, options: lxc_attach_options_t, program: *const c_char, ...) -> c_intRun a program inside a container and wait for it to exit (list variant).
Parameters
c Container.
options See lxc_attach_options_t.
program Full path inside container of program to run.
… Command-line to pass to program (must end in NULL).
Returns
waitpid(2) status of exited process that ran program, or -1 on
error.
version: 1.0.0
snapshot: unsafe extern "C" fn(c: *mut lxc_container, commentfile: *const c_char) -> c_intCreate a container snapshot.
Assuming default paths, snapshots will be created as
/var/lib/lxc/<c>/snaps/snap<n> where <c> represents the container
name and <n> represents the zero-based snapshot number.
Parameters
c Container.
commentfile Full path to file containing a description of the snapshot.
Returns
-1 on error, or zero-based snapshot number.
note: commentfile may be NULL but this is discouraged.
version: 1.0.0
snapshot_list: unsafe extern "C" fn(c: *mut lxc_container, snapshots: *mut *mut lxc_snapshot) -> c_intObtain a list of container snapshots.
Parameters
c Container.
snapshots Dynamically-allocated Array of lxc_snapshot’s.
Returns
Number of snapshots.
note: The array returned in snapshots is allocated, so the caller
must free it.
note: To free an individual snapshot as returned in \p
snapshots, call the snapshots free function (see
src/tests/snapshot.c for an example).
version: 1.0.0
snapshot_restore: unsafe extern "C" fn(c: *mut lxc_container, snapname: *const c_char, newname: *const c_char) -> boolCreate a new container based on a snapshot.
The restored container will be a copy (not snapshot) of the snapshot, and restored in the lxcpath of the original container.
Parameters
c Container.
snapname Name of snapshot.
newname Name to be used for the restored snapshot.
Returns
true on success, else false.
warning: If newname is the same as the current container
name, the container will be destroyed. However, this will
fail if the snapshot is overlay-based, since the snapshots
will pin the original container.
note: As an example, if the container exists as /var/lib/lxc/c1,
snapname might be 'snap0' (representing /var/lib/lxcsnaps/c1/snap0).
If newname is c2, then snap0 will be copied to /var/lib/lxc/c2.
version: 1.0.0
snapshot_destroy: unsafe extern "C" fn(c: *mut lxc_container, snapname: *const c_char) -> boolDestroy the specified snapshot.
Parameters
c Container.
snapname Name of snapshot.
Returns
true on success, else false.
version: 1.0.0
may_control: unsafe extern "C" fn(c: *mut lxc_container) -> boolDetermine if the caller may control the container.
Parameters
c Container.
Returns
false if there is a control socket for the container monitor and the
caller may not access it, otherwise returns true.
version: 1.0.0
add_device_node: unsafe extern "C" fn(c: *mut lxc_container, src_path: *const c_char, dest_path: *const c_char) -> boolAdd specified device to the container.
Parameters
c Container.
src_path Full path of the device.
dest_path Alternate path in the container (or NULL to use
src_path).
Returns
true on success, else false.
version: 1.0.0
remove_device_node: unsafe extern "C" fn(c: *mut lxc_container, src_path: *const c_char, dest_path: *const c_char) -> boolRemove specified device from the container.
Parameters
c Container.
src_path Full path of the device.
dest_path Alternate path in the container (or NULL to use
src_path).
Returns
true on success, else false.
version: 1.0.0
Trait Implementations§
Source§impl Clone for lxc_container
impl Clone for lxc_container
Source§fn clone(&self) -> lxc_container
fn clone(&self) -> lxc_container
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more