Skip to content

Commit

Permalink
Merge pull request #2634 from brauner/2018-09-21/cgroup_relative
Browse files Browse the repository at this point in the history
confile: s/lxc.cgroup.keep/lxc.cgroup.relative/g
  • Loading branch information
stgraber committed Sep 21, 2018
2 parents 0854924 + 9caee12 commit 053f8fb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
20 changes: 10 additions & 10 deletions src/lxc/cgroups/cgfsng.c
Expand Up @@ -1749,7 +1749,7 @@ static bool cgfsng_escape(const struct cgroup_ops *ops, struct lxc_conf *conf)
{
int i;

if (conf->cgroup_meta.keep || geteuid())
if (conf->cgroup_meta.relative || geteuid())
return true;

for (i = 0; ops->hierarchies[i]; i++) {
Expand Down Expand Up @@ -2281,7 +2281,7 @@ static bool cgroup_use_wants_controllers(const struct cgroup_ops *ops,
/* At startup, parse_hierarchies finds all the info we need about cgroup
* mountpoints and current cgroups, and stores it in @d.
*/
static bool cg_hybrid_init(struct cgroup_ops *ops, bool keep)
static bool cg_hybrid_init(struct cgroup_ops *ops, bool relative)
{
int ret;
char *basecginfo;
Expand All @@ -2293,7 +2293,7 @@ static bool cg_hybrid_init(struct cgroup_ops *ops, bool keep)
/* Root spawned containers escape the current cgroup, so use init's
* cgroups as our base in that case.
*/
if (!keep && (geteuid() == 0))
if (!relative && (geteuid() == 0))
basecginfo = read_file("/proc/1/cgroup");
else
basecginfo = read_file("/proc/self/cgroup");
Expand Down Expand Up @@ -2444,12 +2444,12 @@ static int cg_is_pure_unified(void)
}

/* Get current cgroup from /proc/self/cgroup for the cgroupfs v2 hierarchy. */
static char *cg_unified_get_current_cgroup(bool keep)
static char *cg_unified_get_current_cgroup(bool relative)
{
char *basecginfo, *base_cgroup;
char *copy = NULL;

if (!keep && (geteuid() == 0))
if (!relative && (geteuid() == 0))
basecginfo = read_file("/proc/1/cgroup");
else
basecginfo = read_file("/proc/self/cgroup");
Expand All @@ -2473,7 +2473,7 @@ static char *cg_unified_get_current_cgroup(bool keep)
return copy;
}

static int cg_unified_init(struct cgroup_ops *ops, bool keep)
static int cg_unified_init(struct cgroup_ops *ops, bool relative)
{
int ret;
char *mountpoint, *subtree_path;
Expand All @@ -2487,7 +2487,7 @@ static int cg_unified_init(struct cgroup_ops *ops, bool keep)
if (ret != CGROUP2_SUPER_MAGIC)
return 0;

base_cgroup = cg_unified_get_current_cgroup(keep);
base_cgroup = cg_unified_get_current_cgroup(relative);
if (!base_cgroup)
return -EINVAL;
prune_init_scope(base_cgroup);
Expand Down Expand Up @@ -2523,7 +2523,7 @@ static bool cg_init(struct cgroup_ops *ops, struct lxc_conf *conf)
{
int ret;
const char *tmp;
bool keep = conf->cgroup_meta.keep;
bool relative = conf->cgroup_meta.relative;

tmp = lxc_global_config_value("lxc.cgroup.use");
if (tmp) {
Expand All @@ -2539,14 +2539,14 @@ static bool cg_init(struct cgroup_ops *ops, struct lxc_conf *conf)
free(pin);
}

ret = cg_unified_init(ops, keep);
ret = cg_unified_init(ops, relative);
if (ret < 0)
return false;

if (ret == CGROUP2_SUPER_MAGIC)
return true;

return cg_hybrid_init(ops, keep);
return cg_hybrid_init(ops, relative);
}

static bool cgfsng_data_init(struct cgroup_ops *ops)
Expand Down
2 changes: 1 addition & 1 deletion src/lxc/conf.h
Expand Up @@ -77,7 +77,7 @@ struct lxc_cgroup {
struct /* meta */ {
char *controllers;
char *dir;
bool keep;
bool relative;
};
};
};
Expand Down
28 changes: 15 additions & 13 deletions src/lxc/confile.c
Expand Up @@ -92,7 +92,7 @@ lxc_config_define(cap_keep);
lxc_config_define(cgroup_controller);
lxc_config_define(cgroup2_controller);
lxc_config_define(cgroup_dir);
lxc_config_define(cgroup_keep);
lxc_config_define(cgroup_relative);
lxc_config_define(console_buffer_size);
lxc_config_define(console_logfile);
lxc_config_define(console_path);
Expand Down Expand Up @@ -169,7 +169,7 @@ static struct lxc_config_t config[] = {
{ "lxc.cap.keep", set_config_cap_keep, get_config_cap_keep, clr_config_cap_keep, },
{ "lxc.cgroup2", set_config_cgroup2_controller, get_config_cgroup2_controller, clr_config_cgroup2_controller, },
{ "lxc.cgroup.dir", set_config_cgroup_dir, get_config_cgroup_dir, clr_config_cgroup_dir, },
{ "lxc.cgroup.keep", set_config_cgroup_keep, get_config_cgroup_keep, clr_config_cgroup_keep, },
{ "lxc.cgroup.relative", set_config_cgroup_relative, get_config_cgroup_relative, clr_config_cgroup_relative, },
{ "lxc.cgroup", set_config_cgroup_controller, get_config_cgroup_controller, clr_config_cgroup_controller, },
{ "lxc.console.buffer.size", set_config_console_buffer_size, get_config_console_buffer_size, clr_config_console_buffer_size, },
{ "lxc.console.logfile", set_config_console_logfile, get_config_console_logfile, clr_config_console_logfile, },
Expand Down Expand Up @@ -1399,26 +1399,26 @@ static int set_config_cgroup_dir(const char *key, const char *value,
return set_config_string_item(&lxc_conf->cgroup_meta.dir, value);
}

static int set_config_cgroup_keep(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
static int set_config_cgroup_relative(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
{
unsigned int converted;
int ret;

if (lxc_config_value_empty(value))
return clr_config_cgroup_keep(key, lxc_conf, NULL);
return clr_config_cgroup_relative(key, lxc_conf, NULL);

ret = lxc_safe_uint(value, &converted);
if (ret < 0)
return -ret;

if (converted == 1) {
lxc_conf->cgroup_meta.keep = true;
lxc_conf->cgroup_meta.relative = true;
return 0;
}

if (converted == 0) {
lxc_conf->cgroup_meta.keep = false;
lxc_conf->cgroup_meta.relative = false;
return 0;
}

Expand Down Expand Up @@ -3240,11 +3240,12 @@ static int get_config_cgroup_dir(const char *key, char *retv, int inlen,
return fulllen;
}

static inline int get_config_cgroup_keep(const char *key, char *retv, int inlen,
struct lxc_conf *lxc_conf, void *data)
static inline int get_config_cgroup_relative(const char *key, char *retv,
int inlen, struct lxc_conf *lxc_conf,
void *data)
{
return lxc_get_conf_int(lxc_conf, retv, inlen,
lxc_conf->cgroup_meta.keep);
lxc_conf->cgroup_meta.relative);
}

static int get_config_idmaps(const char *key, char *retv, int inlen,
Expand Down Expand Up @@ -3991,10 +3992,11 @@ static int clr_config_cgroup_dir(const char *key, struct lxc_conf *lxc_conf,
return 0;
}

static inline int clr_config_cgroup_keep(const char *key,
struct lxc_conf *lxc_conf, void *data)
static inline int clr_config_cgroup_relative(const char *key,
struct lxc_conf *lxc_conf,
void *data)
{
lxc_conf->cgroup_meta.keep = false;
lxc_conf->cgroup_meta.relative = false;
return 0;
}

Expand Down

0 comments on commit 053f8fb

Please sign in to comment.