]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc_create: support 'lxc-create -t <template> -h'
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 3 Jun 2013 16:19:01 +0000 (18:19 +0200)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 3 Jun 2013 16:22:42 +0000 (11:22 -0500)
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: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/arguments.c
src/lxc/arguments.h
src/lxc/lxc_create.c

index 8a8d3067e2e02410c4e4b57874f002dfb226cbcd..90fbea3a3c7285b23e9bab940e5b515e6e62aff8 100644 (file)
@@ -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);
 }
 
index b01bd08264c97482c917ddd2eef5cd91fb7cfb28..3d1df70b861b2896a79fc88176a168dc4d8d6c3f 100644 (file)
@@ -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;
index f35a664b5f8a412ba9e61cc96c81f751f445d29b..c9231effae4f4be7e1de3a475441066795a963ae 100644 (file)
@@ -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\