]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tools: lxc-execute: share internal API symbols
author2xsec <dh48.jeong@samsung.com>
Fri, 29 Jun 2018 07:10:42 +0000 (16:10 +0900)
committer2xsec <dh48.jeong@samsung.com>
Sat, 30 Jun 2018 09:45:21 +0000 (18:45 +0900)
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
src/lxc/Makefile.am
src/lxc/confile.c
src/lxc/tools/lxc_execute.c

index 6b8ce2cba7ccdb6c15b64210ce31bb1ba92d6552..ec94d14b162889281751ddb8399a26dde40dcd01 100644 (file)
@@ -272,7 +272,7 @@ lxc_config_SOURCES = tools/lxc_config.c tools/arguments.c
 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
index 65409aa884729d33ff8fe7ae5b7b4067075ff7e0..7cb1fbb16a3c6dc003b71b6abbbc8e1ea09facd6 100644 (file)
@@ -2388,6 +2388,74 @@ on_error:
        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;
@@ -2415,7 +2483,12 @@ int lxc_config_define_add(struct lxc_list *defines, char *arg)
        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;
 }
index ecabb785b59d3179aef13c4247c0514dccb0c4a3..2f79b74a9b5d3fd44864280465452b897eadc167 100644 (file)
 #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;
 
@@ -78,6 +82,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
                args->share_ns[LXC_NS_PID] = arg;
                break;
        }
+
        return 0;
 }
 
@@ -117,10 +122,10 @@ Options :\n\
 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;
 
@@ -166,31 +171,33 @@ int main(int argc, char *argv[])
 
        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;
                }
        }
@@ -227,11 +234,13 @@ int main(int argc, char *argv[])
                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 {
@@ -243,7 +252,6 @@ int main(int argc, char *argv[])
                }
        }
 
-
 out:
        lxc_container_put(c);
        exit(err);