lxc_config_define(monitor);
lxc_config_define(group);
lxc_config_define(environment);
+lxc_config_define(execute_cmd);
lxc_config_define(init_cmd);
lxc_config_define(init_uid);
lxc_config_define(init_gid);
{ "lxc.console.path", false, set_config_console_path, get_config_console_path, clr_config_console_path, },
{ "lxc.environment", false, set_config_environment, get_config_environment, clr_config_environment, },
{ "lxc.ephemeral", false, set_config_ephemeral, get_config_ephemeral, clr_config_ephemeral, },
+ { "lxc.execute.cmd", false, set_config_execute_cmd, get_config_execute_cmd, clr_config_execute_cmd, },
{ "lxc.group", false, set_config_group, get_config_group, clr_config_group, },
{ "lxc.hook.autodev", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.clone", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
return set_config_path_item(&lxc_conf->seccomp, value);
}
+static int set_config_execute_cmd(const char *key, const char *value,
+ struct lxc_conf *lxc_conf, void *data)
+{
+ return set_config_path_item(&lxc_conf->execute_cmd, value);
+}
+
static int set_config_init_cmd(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
{
return fulllen;
}
+static int get_config_execute_cmd(const char *key, char *retv, int inlen,
+ struct lxc_conf *c, void *data)
+{
+ return lxc_get_conf_str(retv, inlen, c->execute_cmd);
+}
+
static int get_config_init_cmd(const char *key, char *retv, int inlen,
struct lxc_conf *c, void *data)
{
return lxc_clear_environment(c);
}
+static inline int clr_config_execute_cmd(const char *key, struct lxc_conf *c,
+ void *data)
+{
+ free(c->execute_cmd);
+ c->execute_cmd = NULL;
+ return 0;
+}
+
static inline int clr_config_init_cmd(const char *key, struct lxc_conf *c,
void *data)
{
static struct lxc_list defines;
-static int my_checker(const struct lxc_arguments* args)
-{
- if (!args->argc) {
- lxc_error(args, "missing command to execute !");
- return -1;
- }
-
- return 0;
-}
-
static int my_parser(struct lxc_arguments* args, int c, char* arg)
{
switch (c) {
-g, --gid=GID Execute COMMAND with GID inside the container\n",
.options = my_longopts,
.parser = my_parser,
- .checker = my_checker,
};
+static bool set_argv(struct lxc_conf *conf, struct lxc_arguments *args)
+{
+ char **components, **p;
+
+ if (!conf->execute_cmd)
+ return false;
+
+ /* TODO -
+ we should honor '"' etc; This seems worth a new helper in utils.c.
+ */
+ components = lxc_string_split(conf->execute_cmd, ' ');
+ if (!components)
+ return false;
+
+ args->argv = components;
+ for (p = components; *p; p++)
+ args->argc++;
+
+ return true;
+}
+
int main(int argc, char *argv[])
{
struct lxc_container *c;
}
}
+ if (my_args.argc == 0) {
+ if (!set_argv(c->lxc_conf, &my_args)) {
+ ERROR("missing command to execute!");
+ lxc_container_put(c);
+ exit(EXIT_FAILURE);
+ }
+ }
+
if (my_args.uid)
c->lxc_conf->init_uid = my_args.uid;