lxc_console_SOURCES = tools/lxc_console.c tools/arguments.c
lxc_destroy_SOURCES = tools/lxc_destroy.c tools/arguments.c
lxc_device_SOURCES = tools/lxc_device.c tools/arguments.c
-lxc_execute_SOURCES = tools/lxc_execute.c tools/arguments.c tools/tool_utils.c
+lxc_execute_SOURCES = tools/lxc_execute.c tools/arguments.c
lxc_freeze_SOURCES = tools/lxc_freeze.c tools/arguments.c
lxc_info_SOURCES = tools/lxc_info.c tools/arguments.c
lxc_monitor_SOURCES = tools/lxc_monitor.c tools/arguments.c tools/tool_utils.c
return ret;
}
+static struct new_config_item *parse_new_conf_line(char *buffer)
+{
+ char *dot, *key, *line, *linep, *value;
+ int ret = 0;
+ char *dup = buffer;
+ struct new_config_item *new = NULL;
+
+ linep = line = strdup(dup);
+ if (!line)
+ return NULL;
+
+ line += lxc_char_left_gc(line, strlen(line));
+
+ /* martian option - don't add it to the config itself */
+ if (strncmp(line, "lxc.", strlen(line)))
+ goto on_error;
+
+ ret = -1;
+ dot = strchr(line, '=');
+ if (!dot) {
+ ERROR("Invalid configuration item: %s", line);
+ goto on_error;
+ }
+
+ *dot = '\0';
+ value = dot + 1;
+
+ key = line;
+ key[lxc_char_right_gc(key, strlen(key))] = '\0';
+
+ value += lxc_char_left_gc(value, strlen(value));
+ value[lxc_char_right_gc(value, strlen(value))] = '\0';
+
+ if (*value == '\'' || *value == '\"') {
+ size_t len;
+
+ len = strlen(value);
+ if (len > 1 && value[len - 1] == *value) {
+ value[len - 1] = '\0';
+ value++;
+ }
+ }
+
+ ret = -1;
+ new = malloc(sizeof(struct new_config_item));
+ if (!new)
+ goto on_error;
+
+ new->key = strdup(key);
+ new->val = strdup(value);
+ if (!new->val || !new->key)
+ goto on_error;
+
+ ret = 0;
+
+on_error:
+ free(linep);
+
+ if (ret < 0 && new) {
+ free(new->key);
+ free(new->val);
+ free(new);
+ new = NULL;
+ }
+
+ return new;
+}
+
int lxc_config_read(const char *file, struct lxc_conf *conf, bool from_include)
{
int ret;
if (!dent)
return -1;
- dent->elem = arg;
+ dent->elem = parse_new_conf_line(arg);
+ if (!dent->elem) {
+ free(dent);
+ return -1;
+ }
+
lxc_list_add_tail(defines, dent);
return 0;
}
#include <lxc/lxccontainer.h>
#include "arguments.h"
-#include "tool_list.h"
-#include "tool_utils.h"
+#include "caps.h"
+#include "confile.h"
+#include "log.h"
+#include "utils.h"
+
+lxc_log_define(lxc_execute, lxc);
static struct lxc_list defines;
-static int my_parser(struct lxc_arguments* args, int c, char* arg)
+static int my_parser(struct lxc_arguments *args, int c, char *arg)
{
int ret;
args->share_ns[LXC_NS_PID] = arg;
break;
}
+
return 0;
}
static bool set_argv(struct lxc_container *c, struct lxc_arguments *args)
{
int ret;
- char buf[TOOL_MAXPATHLEN];
+ char buf[MAXPATHLEN];
char **components, **p;
- ret = c->get_config_item(c, "lxc.execute.cmd", buf, TOOL_MAXPATHLEN);
+ ret = c->get_config_item(c, "lxc.execute.cmd", buf, MAXPATHLEN);
if (ret < 0)
return false;
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {
- fprintf(stderr, "Failed to create lxc_container\n");
+ ERROR("Failed to create lxc_container");
exit(err);
}
if (my_args.rcfile) {
c->clear_config(c);
+
if (!c->load_config(c, my_args.rcfile)) {
- fprintf(stderr, "Failed to load rcfile\n");
+ ERROR("Failed to load rcfile");
goto out;
}
+
c->configfile = strdup(my_args.rcfile);
if (!c->configfile) {
- fprintf(stderr, "Out of memory setting new config filename\n");
+ ERROR("Out of memory setting new config filename");
goto out;
}
}
if (!c->lxc_conf) {
- fprintf(stderr, "Executing a container with no configuration file may crash the host\n");
+ ERROR("Executing a container with no configuration file may crash the host");
goto out;
}
if (my_args.argc == 0) {
if (!set_argv(c, &my_args)) {
- fprintf(stderr, "missing command to execute!\n");
+ ERROR("Missing command to execute!");
goto out;
}
}
goto out;
c->daemonize = my_args.daemonize == 1;
+
bret = c->start(c, 1, my_args.argv);
if (!bret) {
- fprintf(stderr, "Failed run an application inside container\n");
+ ERROR("Failed run an application inside container");
goto out;
}
+
if (c->daemonize) {
err = EXIT_SUCCESS;
} else {
}
}
-
out:
lxc_container_put(c);
exit(err);