Commit f002c8a7 by Serge Hallyn

lxc_create: support 'lxc-create -t <template> -h'

With the lxc-create script, 'lxc-create -t template -h' used to call 'template -h' to get template-specific help. The api based lxc-create did not yet support that. Add a 'helpfn' method to the lxc_arguments, which is called at the end of printhelp, and passed the lxc_arguments. Use that in lxc_create to reintroduce the desired behavior. Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent 4c1f6b67
......@@ -147,6 +147,8 @@ for any corresponding short options.\n\
See the %s man page for further information.\n\n",
args->progname, args->help, args->progname);
if (args->helpfn)
args->helpfn(args);
exit(code);
}
......
......@@ -33,6 +33,7 @@ typedef int (*lxc_arguments_checker_t) (const struct lxc_arguments *);
struct lxc_arguments {
const char *help;
void(*helpfn)(const struct lxc_arguments *);
const char *progname;
const struct option* options;
lxc_arguments_parser_t parser;
......
......@@ -85,8 +85,35 @@ static const struct option my_longopts[] = {
LXC_COMMON_OPTIONS
};
static void create_helpfn(const struct lxc_arguments *args) {
char *argv[3], *path;
size_t len;
int ret;
pid_t pid;
if (!args->template)
return;
if ((pid = fork()) < 0)
return;
if (pid)
wait_for_pid(pid);
len = strlen(LXCTEMPLATEDIR) + strlen(args->template) + strlen("/lxc-") + 1;
path = alloca(len);
ret = snprintf(path, len, "%s/lxc-%s", LXCTEMPLATEDIR, args->template);
if (ret < 0 || ret >= len)
return;
argv[0] = path;
argv[1] = "-h";
argv[2] = NULL;
execv(path, argv);
ERROR("Error executing %s -h", path);
exit(1);
}
static struct lxc_arguments my_args = {
.progname = "lxc-create",
.helpfn = create_helpfn,
.help = "\
--name=NAME [-w] [-r] [-t timeout] [-P lxcpath]\n\
\n\
......
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