Commit d3cf9a1b by Stéphane Graber Committed by GitHub

Merge pull request #1829 from brauner/2017-09-24/stable_2.0_backports

stable 2.0: backports
parents 7d9d482b bab07a29
......@@ -1398,6 +1398,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
<listitem><para> LXC_CONFIG_FILE: the path to the container configuration file. </para></listitem>
<listitem><para> LXC_SRC_NAME: in the case of the clone hook, this is the original container's name. </para></listitem>
<listitem><para> LXC_ROOTFS_PATH: this is the lxc.rootfs entry for the container. Note this is likely not where the mounted rootfs is to be found, use LXC_ROOTFS_MOUNT for that. </para></listitem>
<listitem><para> LXC_CGNS_AWARE: indicated whether the container is cgroup namespace aware. </para></listitem>
<listitem><para> LXC_LOG_LEVEL: the container's log level. </para></listitem>
</itemizedlist>
</para>
<para>
......
......@@ -1913,21 +1913,28 @@ static int cgfsng_set(const char *filename, const char *value, const char *name,
*/
static int lxc_cgroup_set_data(const char *filename, const char *value, struct cgfsng_handler_data *d)
{
char *subsystem = NULL, *p;
int ret = -1;
char *fullpath, *p;
struct hierarchy *h;
int ret = 0;
char *controller = NULL;
subsystem = alloca(strlen(filename) + 1);
strcpy(subsystem, filename);
if ((p = strchr(subsystem, '.')) != NULL)
controller = alloca(strlen(filename) + 1);
strcpy(controller, filename);
if ((p = strchr(controller, '.')) != NULL)
*p = '\0';
h = get_hierarchy(subsystem);
if (h) {
char *fullpath = must_make_path(h->fullcgpath, filename, NULL);
h = get_hierarchy(controller);
if (!h) {
ERROR("Failed to setup limits for the \"%s\" controller. "
"The controller seems to be unused by \"cgfsng\" cgroup "
"driver or not enabled on the cgroup hierarchy",
controller);
return -1;
}
fullpath = must_make_path(h->fullcgpath, filename, NULL);
ret = lxc_write_to_file(fullpath, value, strlen(value), false);
free(fullpath);
}
return ret;
}
......
......@@ -723,7 +723,7 @@ static const struct dev_symlinks dev_symlinks[] = {
{"/proc/self/fd/2", "stderr"},
};
static int setup_dev_symlinks(const struct lxc_rootfs *rootfs)
static int lxc_setup_dev_symlinks(const struct lxc_rootfs *rootfs)
{
char path[MAXPATHLEN];
int ret,i;
......@@ -3159,8 +3159,10 @@ int lxc_setup(struct lxc_handler *handler)
}
}
if (!lxc_conf->is_execute && lxc_setup_console(&lxc_conf->rootfs, &lxc_conf->console, lxc_conf->ttydir)) {
ERROR("failed to setup the console for '%s'", name);
ret = lxc_setup_console(&lxc_conf->rootfs, &lxc_conf->console,
lxc_conf->ttydir);
if (ret < 0) {
ERROR("Failed to setup console");
return -1;
}
......@@ -3169,8 +3171,9 @@ int lxc_setup(struct lxc_handler *handler)
ERROR("failed to setup kmsg for '%s'", name);
}
if (!lxc_conf->is_execute && setup_dev_symlinks(&lxc_conf->rootfs)) {
ERROR("failed to setup /dev symlinks for '%s'", name);
ret = lxc_setup_dev_symlinks(&lxc_conf->rootfs);
if (ret < 0) {
ERROR("Failed to setup /dev symlinks");
return -1;
}
......
......@@ -2299,44 +2299,51 @@ struct parse_line_conf {
static int parse_line(char *buffer, void *data)
{
struct lxc_config_t *config;
char *dot, *key, *line, *linep, *value;
struct parse_line_conf *plc = data;
bool empty_line;
struct lxc_config_t *config;
int ret = 0;
char *dup = buffer;
struct parse_line_conf *plc = data;
if (lxc_is_line_empty(buffer))
return 0;
/* If there are newlines in the config file we should keep them. */
empty_line = lxc_is_line_empty(dup);
if (empty_line)
dup = "\n";
/* we have to dup the buffer otherwise, at the re-exec for
* reboot we modified the original string on the stack by
* replacing '=' by '\0' below
*/
linep = line = strdup(buffer);
if (!line) {
SYSERROR("failed to allocate memory for '%s'", buffer);
if (!line)
return -1;
if (!plc->from_include) {
ret = append_unexp_config_line(line, plc->conf);
if (ret < 0)
goto on_error;
}
if (!plc->from_include)
if ((ret = append_unexp_config_line(line, plc->conf)))
goto out;
if (empty_line)
return 0;
line += lxc_char_left_gc(line, strlen(line));
/* ignore comments */
if (line[0] == '#')
goto out;
goto on_error;
/* martian option - don't add it to the config itself */
if (strncmp(line, "lxc.", 4))
goto out;
goto on_error;
ret = -1;
dot = strstr(line, "=");
dot = strchr(line, '=');
if (!dot) {
ERROR("invalid configuration line: %s", line);
goto out;
ERROR("Invalid configuration line: %s", line);
goto on_error;
}
*dot = '\0';
......@@ -2358,13 +2365,13 @@ static int parse_line(char *buffer, void *data)
config = lxc_getconfig(key);
if (!config) {
ERROR("unknown key %s", key);
goto out;
ERROR("Unknown configuration key \"%s\"", key);
goto on_error;
}
ret = config->set(key, value, plc->conf, data);
out:
on_error:
free(linep);
return ret;
}
......
......@@ -228,11 +228,6 @@ extern int lxc_console_mainloop_add(struct lxc_epoll_descr *descr,
{
struct lxc_console *console = &conf->console;
if (conf->is_execute) {
INFO("no console for lxc-execute.");
return 0;
}
if (!conf->rootfs.path) {
INFO("no rootfs, no console.");
return 0;
......@@ -526,11 +521,6 @@ int lxc_console_create(struct lxc_conf *conf)
struct lxc_console *console = &conf->console;
int ret;
if (conf->is_execute) {
INFO("not allocating a console device for lxc-execute.");
return 0;
}
if (!conf->rootfs.path) {
INFO("container does not have a rootfs, console device will be shared with the host");
return 0;
......
......@@ -922,7 +922,6 @@ int netdev_get_mtu(int ifindex)
goto out;
recv_len = err;
err = 0;
/* Satisfy the typing for the netlink macros */
msg = answer->nlmsghdr;
......@@ -1363,7 +1362,6 @@ int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr)
data = (unsigned char *)sockaddr->sa_data;
while ((*macaddr != '\0') && (i < ETH_ALEN)) {
val = 0;
c = *macaddr++;
if (isdigit(c))
val = c - '0';
......
......@@ -136,8 +136,8 @@ int aufs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
rdata.src = odelta;
rdata.dest = ndelta;
if (am_unpriv())
ret = userns_exec_1(conf, rsync_delta_wrapper, &rdata,
"rsync_delta_wrapper");
ret = userns_exec_full(conf, rsync_delta_wrapper,
&rdata, "rsync_delta_wrapper");
else
ret = rsync_delta(&rdata);
if (ret) {
......
......@@ -397,7 +397,7 @@ int btrfs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
return btrfs_snapshot(orig->dest, new->dest);
sdata.dest = new->dest;
sdata.src = orig->dest;
return userns_exec_1(conf, btrfs_snapshot_wrapper, &sdata,
return userns_exec_full(conf, btrfs_snapshot_wrapper, &sdata,
"btrfs_snapshot_wrapper");
}
......
......@@ -752,7 +752,7 @@ static int ovl_do_rsync(struct lxc_storage *orig, struct lxc_storage *new,
rdata.orig = orig;
rdata.new = new;
if (am_unpriv())
ret = userns_exec_1(conf, ovl_rsync_wrapper, &rdata,
ret = userns_exec_full(conf, ovl_rsync_wrapper, &rdata,
"ovl_rsync_wrapper");
else
ret = ovl_rsync(&rdata);
......
......@@ -312,9 +312,14 @@ struct lxc_storage *storage_copy(struct lxc_container *c0, const char *cname,
const char *oldpath = c0->config_path;
struct rsync_data data;
/* if the container name doesn't show up in the rootfs path, then
* we don't know how to come up with a new name
/* If the container name doesn't show up in the rootfs path, then we
* don't know how to come up with a new name.
*/
if (!src) {
ERROR("No rootfs specified");
return NULL;
}
if (strstr(src, oldname) == NULL) {
ERROR(
"original rootfs path %s doesn't include container name %s",
......@@ -454,8 +459,8 @@ struct lxc_storage *storage_copy(struct lxc_container *c0, const char *cname,
data.orig = orig;
data.new = new;
if (am_unpriv())
ret = userns_exec_1(c0->lxc_conf, rsync_rootfs_wrapper, &data,
"rsync_rootfs_wrapper");
ret = userns_exec_full(c0->lxc_conf, rsync_rootfs_wrapper,
&data, "rsync_rootfs_wrapper");
else
ret = rsync_rootfs(&data);
......
......@@ -128,7 +128,6 @@ extern struct lxc_storage *storage_create(const char *dest, const char *type,
extern void storage_put(struct lxc_storage *bdev);
extern bool storage_destroy(struct lxc_conf *conf);
/* callback function to be used with userns_exec_1() */
extern int storage_destroy_wrapper(void *data);
extern bool rootfs_is_blockdev(struct lxc_conf *conf);
......
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