Commit 4878dac4 by Stéphane Graber Committed by Serge Hallyn

Set default paths for unprivileged use (v2)

When running unprivileged (euid != 0), LXC will now use the following paths: - Default lxc path: ~/.local/share/lxc/ - Default config path: ~/.config/lxc/lxc.conf Those two paths are based on standard XDG paths (though ignoring all the possible override paths for now at least) and so probably don't need to be configurable at build time. Signed-off-by: 's avatarStéphane Graber <stgraber@ubuntu.com> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent 619256b5
...@@ -248,11 +248,36 @@ const char *lxc_global_config_value(const char *option_name) ...@@ -248,11 +248,36 @@ const char *lxc_global_config_value(const char *option_name)
{ "lvm_vg", DEFAULT_VG }, { "lvm_vg", DEFAULT_VG },
{ "lvm_thin_pool", DEFAULT_THIN_POOL }, { "lvm_thin_pool", DEFAULT_THIN_POOL },
{ "zfsroot", DEFAULT_ZFSROOT }, { "zfsroot", DEFAULT_ZFSROOT },
{ "lxcpath", LXCPATH }, { "lxcpath", NULL },
{ "cgroup.pattern", DEFAULT_CGROUP_PATTERN }, { "cgroup.pattern", DEFAULT_CGROUP_PATTERN },
{ "cgroup.use", NULL }, { "cgroup.use", NULL },
{ NULL, NULL }, { NULL, NULL },
}; };
char *user_config_path = NULL;
char *user_lxc_path = NULL;
char *user_home = NULL;
if (geteuid() > 0) {
user_home = getenv("HOME");
if (user_home)
user_home = strdup(user_home);
else
user_home = "/";
user_config_path = malloc(sizeof(char) * (22 + strlen(user_home)));
user_lxc_path = malloc(sizeof(char) * (19 + strlen(user_home)));
sprintf(user_config_path, "%s/.config/lxc/lxc.conf", user_home);
sprintf(user_lxc_path, "%s/.local/share/lxc/", user_home);
free(user_home);
}
else {
user_config_path = strdup(LXC_GLOBAL_CONF);
user_lxc_path = strdup(LXCPATH);
}
/* placed in the thread local storage pool */ /* placed in the thread local storage pool */
static __thread const char *values[sizeof(options) / sizeof(options[0])] = { 0 }; static __thread const char *values[sizeof(options) / sizeof(options[0])] = { 0 };
const char *(*ptr)[2]; const char *(*ptr)[2];
...@@ -266,17 +291,23 @@ const char *lxc_global_config_value(const char *option_name) ...@@ -266,17 +291,23 @@ const char *lxc_global_config_value(const char *option_name)
break; break;
} }
if (!(*ptr)[0]) { if (!(*ptr)[0]) {
free(user_config_path);
free(user_lxc_path);
errno = EINVAL; errno = EINVAL;
return NULL; return NULL;
} }
if (values[i]) { if (values[i]) {
free(user_config_path);
free(user_lxc_path);
value = values[i]; value = values[i];
return value; return value;
} }
process_lock(); process_lock();
fin = fopen_cloexec(LXC_GLOBAL_CONF, "r"); fin = fopen_cloexec(user_config_path, "r");
free(user_config_path);
process_unlock(); process_unlock();
if (fin) { if (fin) {
while (fgets(buf, 1024, fin)) { while (fgets(buf, 1024, fin)) {
...@@ -311,11 +342,17 @@ const char *lxc_global_config_value(const char *option_name) ...@@ -311,11 +342,17 @@ const char *lxc_global_config_value(const char *option_name)
if (!*p) if (!*p)
continue; continue;
values[i] = copy_global_config_value(p); values[i] = copy_global_config_value(p);
free(user_lxc_path);
goto out; goto out;
} }
} }
/* could not find value, use default */ /* could not find value, use default */
if (strcmp(option_name, "lxcpath") == 0)
values[i] = user_lxc_path;
else {
free(user_lxc_path);
values[i] = (*ptr)[1]; values[i] = (*ptr)[1];
}
/* special case: if default value is NULL, /* special case: if default value is NULL,
* and there is no config, don't view that * and there is no config, don't view that
* as an error... */ * as an error... */
......
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