libcgroup
Loading...
Searching...
No Matches
5. Configuration

Configuration file

libcgroup can mount and create control groups and set their parameters as specified in a configuration file.

Todo
add this description?: These functions are mostly intended to be used by internal libcgroup tools, however they are fully supported and applications can benefit from them.
int cgroup_config_load_config (const char *pathname)
 
int cgroup_unload_cgroups (void)
 
int cgroup_config_unload_config (const char *pathname, int flags)
 
int cgroup_config_set_default (struct cgroup *new_default)
 
int cgroup_init_templates_cache (char *pathname)
 
int cgroup_reload_cached_templates (char *pathname)
 
int cgroup_load_templates_cache_from_files (int *file_index)
 
void cgroup_templates_cache_set_source_files (struct cgroup_string_list *tmpl_files)
 
int cgroup_config_create_template_group (struct cgroup *cgrp, char *template_name, int flags)
 

Detailed Description

Function Documentation

◆ cgroup_config_create_template_group()

int cgroup_config_create_template_group ( struct cgroup * cgrp,
char * template_name,
int flags )

Physically create a new control group in kernel, based on given control group template and configuration file. If given template is not set in configuration file, then the procedure works create the control group using cgroup_create_cgroup() function

Templates are loaded using cgroup_load_templates_cache_from_files function, which must be preceded by cgroup_templates_cache_set_source_files call.

The flags can alter the behavior of this function: CGFLAG_USE_TEMPLATE_CACHE: Use cached templates instead of parsing the config file

Parameters
pathnameName of the configuration file with template definitions
cgroupWanted control group - contains substitute name and wanted controllers.
template_nameTemplate name used for cgroup setting
flagsBit flags to change the behavior

◆ cgroup_config_load_config()

int cgroup_config_load_config ( const char * pathname)

Load configuration file and mount and create control groups described there. See cgconfig.conf man page for format of the file.

Parameters
pathnameName of the configuration file to load.

◆ cgroup_config_set_default()

int cgroup_config_set_default ( struct cgroup * new_default)

Sets default permissions of groups created by subsequent cgroup_config_load_config() calls. If a config file contains a 'default {}' section, the default permissions from the config file is then used.

Use cgroup_new_cgroup() to create a dummy group and cgroup_set_uid_gid() and cgroup_set_permissions() to set its permissions. Use NO_UID_GID instead of GID/UID and NO_PERMS instead of file/directory permissions to let kernel decide the default permissions where you don't want specific user and/or permissions. Kernel then uses current user/group and permissions from umask then.

Parameters
new_defaultNew default permissions from this group are copied to libcgroup internal structures. I.e., this group can be freed immediately after this function returns.

◆ cgroup_config_unload_config()

int cgroup_config_unload_config ( const char * pathname,
int flags )

Delete all cgroups and unmount all mount points defined in specified config file.

The groups are either removed recursively or only the empty ones, based on given flags. Mount point are always umounted only if they are empty, regardless of any flags.

The groups are sorted before they are removed, so the removal of empty ones actually works (i.e. subgroups are removed first).

Parameters
pathnameName of the configuration file to unload.
flagsCombination of CGFLAG_DELETE_* flags, which indicate what and how to delete.

◆ cgroup_init_templates_cache()

int cgroup_init_templates_cache ( char * pathname)

Initializes the templates cache and load it from file pathname.

Initializes the templates cache.

Returns
0 on success, > 0 on error

◆ cgroup_load_templates_cache_from_files()

int cgroup_load_templates_cache_from_files ( int * file_index)

Load the templates cache from files. Before calling this function, cgroup_templates_cache_set_source_files has to be called first.

Parameters
file_indexindex of file which was unable to be parsed
Returns
0 on success, > 0 on error

◆ cgroup_reload_cached_templates()

int cgroup_reload_cached_templates ( char * pathname)

Reloads the templates list from file pathname.

Reloads the templates list, using the given configuration file.

Returns
0 on success, > 0 on failure

◆ cgroup_templates_cache_set_source_files()

void cgroup_templates_cache_set_source_files ( struct cgroup_string_list * tmpl_files)

Setting source files of templates. This function has to be called before any call of cgroup_load_templates_cache_from_files.

Parameters
tmpl_files

◆ cgroup_unload_cgroups()

int cgroup_unload_cgroups ( void )

Delete all control groups and unmount all hierarchies.