Commit 5e1c5795 by KATOH Yasufumi Committed by Serge Hallyn

lxc_global_config_value can return the default lxc.cgroup.pattern whether root or non-root

>>> On Tue, 30 Sep 2014 19:48:09 +0000 in message "Re: [lxc-devel] [PATCH] lxc-config can show lxc.cgroup.(use|pattern)" Serge Hallyn-san wrote: > I think it would be worth also augmenting > lxc_global_config_value() to return a default lxc.cgroup.use > for 'all', and a default lxc.cgroup.pattern ("/lxc/%n" for root > or "%n" for non-root). lxc.cgroup.pattern is like this? (^_^;) Signed-off-by: 's avatarKATOH Yasufumi <karma@jazz.email.ne.jp> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent 0c3720a3
...@@ -2226,15 +2226,7 @@ static void *cgfs_init(const char *name) ...@@ -2226,15 +2226,7 @@ static void *cgfs_init(const char *name)
if (!d->name) if (!d->name)
goto err1; goto err1;
/* if we are running as root, use system cgroup pattern, otherwise d->cgroup_pattern = lxc_global_config_value("lxc.cgroup.pattern");
* just create a cgroup under the current one. But also fall back to
* that if for some reason reading the configuration fails and no
* default value is available
*/
if (geteuid() == 0)
d->cgroup_pattern = lxc_global_config_value("lxc.cgroup.pattern");
if (!d->cgroup_pattern)
d->cgroup_pattern = "%n";
d->meta = lxc_cgroup_load_meta(); d->meta = lxc_cgroup_load_meta();
if (!d->meta) { if (!d->meta) {
......
...@@ -532,15 +532,8 @@ static void *cgm_init(const char *name) ...@@ -532,15 +532,8 @@ static void *cgm_init(const char *name)
goto err1; goto err1;
} }
/* if we are running as root, use system cgroup pattern, otherwise d->cgroup_pattern = lxc_global_config_value("lxc.cgroup.pattern");
* just create a cgroup under the current one. But also fall back to
* that if for some reason reading the configuration fails and no
* default value is available
*/
if (geteuid() == 0)
d->cgroup_pattern = lxc_global_config_value("lxc.cgroup.pattern");
if (!d->cgroup_pattern)
d->cgroup_pattern = "%n";
// cgm_create immediately gets called so keep the connection open // cgm_create immediately gets called so keep the connection open
return d; return d;
......
...@@ -266,7 +266,7 @@ const char *lxc_global_config_value(const char *option_name) ...@@ -266,7 +266,7 @@ const char *lxc_global_config_value(const char *option_name)
{ "lxc.bdev.zfs.root", DEFAULT_ZFSROOT }, { "lxc.bdev.zfs.root", DEFAULT_ZFSROOT },
{ "lxc.lxcpath", NULL }, { "lxc.lxcpath", NULL },
{ "lxc.default_config", NULL }, { "lxc.default_config", NULL },
{ "lxc.cgroup.pattern", DEFAULT_CGROUP_PATTERN }, { "lxc.cgroup.pattern", NULL },
{ "lxc.cgroup.use", NULL }, { "lxc.cgroup.use", NULL },
{ NULL, NULL }, { NULL, NULL },
}; };
...@@ -280,6 +280,7 @@ const char *lxc_global_config_value(const char *option_name) ...@@ -280,6 +280,7 @@ const char *lxc_global_config_value(const char *option_name)
char *user_config_path = NULL; char *user_config_path = NULL;
char *user_default_config_path = NULL; char *user_default_config_path = NULL;
char *user_lxc_path = NULL; char *user_lxc_path = NULL;
char *user_cgroup_pattern = NULL;
if (geteuid() > 0) { if (geteuid() > 0) {
const char *user_home = getenv("HOME"); const char *user_home = getenv("HOME");
...@@ -293,11 +294,13 @@ const char *lxc_global_config_value(const char *option_name) ...@@ -293,11 +294,13 @@ const char *lxc_global_config_value(const char *option_name)
sprintf(user_config_path, "%s/.config/lxc/lxc.conf", user_home); sprintf(user_config_path, "%s/.config/lxc/lxc.conf", user_home);
sprintf(user_default_config_path, "%s/.config/lxc/default.conf", user_home); sprintf(user_default_config_path, "%s/.config/lxc/default.conf", user_home);
sprintf(user_lxc_path, "%s/.local/share/lxc/", user_home); sprintf(user_lxc_path, "%s/.local/share/lxc/", user_home);
user_cgroup_pattern = strdup("%n");
} }
else { else {
user_config_path = strdup(LXC_GLOBAL_CONF); user_config_path = strdup(LXC_GLOBAL_CONF);
user_default_config_path = strdup(LXC_DEFAULT_CONFIG); user_default_config_path = strdup(LXC_DEFAULT_CONFIG);
user_lxc_path = strdup(LXCPATH); user_lxc_path = strdup(LXCPATH);
user_cgroup_pattern = strdup(DEFAULT_CGROUP_PATTERN);
} }
const char * const (*ptr)[2]; const char * const (*ptr)[2];
...@@ -313,6 +316,7 @@ const char *lxc_global_config_value(const char *option_name) ...@@ -313,6 +316,7 @@ const char *lxc_global_config_value(const char *option_name)
free(user_config_path); free(user_config_path);
free(user_default_config_path); free(user_default_config_path);
free(user_lxc_path); free(user_lxc_path);
free(user_cgroup_pattern);
errno = EINVAL; errno = EINVAL;
return NULL; return NULL;
} }
...@@ -321,6 +325,7 @@ const char *lxc_global_config_value(const char *option_name) ...@@ -321,6 +325,7 @@ const char *lxc_global_config_value(const char *option_name)
free(user_config_path); free(user_config_path);
free(user_default_config_path); free(user_default_config_path);
free(user_lxc_path); free(user_lxc_path);
free(user_cgroup_pattern);
return values[i]; return values[i];
} }
...@@ -379,14 +384,22 @@ const char *lxc_global_config_value(const char *option_name) ...@@ -379,14 +384,22 @@ const char *lxc_global_config_value(const char *option_name)
remove_trailing_slashes(user_lxc_path); remove_trailing_slashes(user_lxc_path);
values[i] = user_lxc_path; values[i] = user_lxc_path;
free(user_default_config_path); free(user_default_config_path);
free(user_cgroup_pattern);
} }
else if (strcmp(option_name, "lxc.default_config") == 0) { else if (strcmp(option_name, "lxc.default_config") == 0) {
values[i] = user_default_config_path; values[i] = user_default_config_path;
free(user_lxc_path); free(user_lxc_path);
free(user_cgroup_pattern);
}
else if (strcmp(option_name, "lxc.cgroup.pattern") == 0) {
values[i] = user_cgroup_pattern;
free(user_default_config_path);
free(user_lxc_path);
} }
else { else {
free(user_default_config_path); free(user_default_config_path);
free(user_lxc_path); free(user_lxc_path);
free(user_cgroup_pattern);
values[i] = (*ptr)[1]; values[i] = (*ptr)[1];
} }
/* special case: if default value is NULL, /* special case: if default value is NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment