mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-11 23:30:41 +00:00
tools: lxc-execute: share internal API symbols
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
This commit is contained in:
parent
a9cb0fb86f
commit
d899f11b7b
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -36,12 +36,16 @@
|
||||
#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);
|
||||
|
Loading…
Reference in New Issue
Block a user