]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Fix lxc-create -h with absolute template path
authorStéphane Graber <stgraber@ubuntu.com>
Wed, 28 Jan 2015 08:28:22 +0000 (09:28 +0100)
committerStéphane Graber <stgraber@ubuntu.com>
Wed, 28 Jan 2015 11:47:12 +0000 (12:47 +0100)
Close #421

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxc_create.c
src/lxc/lxccontainer.c
src/lxc/utils.c
src/lxc/utils.h

index 2cc866a32d730c3fd9039047fc2f2f8709100818..8f46db941d0457c0ad4a059b006cf1de6a266785 100644 (file)
@@ -101,8 +101,6 @@ static const struct option my_longopts[] = {
 
 static void create_helpfn(const struct lxc_arguments *args) {
        char *argv[3], *path;
-       size_t len;
-       int ret;
        pid_t pid;
 
        if (!args->template)
@@ -114,11 +112,7 @@ static void create_helpfn(const struct lxc_arguments *args) {
                return;
        }
 
-       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;
+       path = get_template_path(args->template);
 
        argv[0] = path;
        argv[1] = "-h";
index 2b3e28c13c1dabdf744d92ab6e6b3048e183ba36..4da1627c3da9df1989563dc8e279fb031b420781 100644 (file)
@@ -841,40 +841,6 @@ static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
        return bdev;
 }
 
-/*
- * Given the '-t' template option to lxc-create, figure out what to
- * do.  If the template is a full executable path, use that.  If it
- * is something like 'sshd', then return $templatepath/lxc-sshd.
- * On success return the template, on error return NULL.
- */
-static char *get_template_path(const char *t)
-{
-       int ret, len;
-       char *tpath;
-
-       if (t[0] == '/' && access(t, X_OK) == 0) {
-               tpath = strdup(t);
-               return tpath;
-       }
-
-       len = strlen(LXCTEMPLATEDIR) + strlen(t) + strlen("/lxc-") + 1;
-       tpath = malloc(len);
-       if (!tpath)
-               return NULL;
-       ret = snprintf(tpath, len, "%s/lxc-%s", LXCTEMPLATEDIR, t);
-       if (ret < 0 || ret >= len) {
-               free(tpath);
-               return NULL;
-       }
-       if (access(tpath, X_OK) < 0) {
-               SYSERROR("bad template: %s", t);
-               free(tpath);
-               return NULL;
-       }
-
-       return tpath;
-}
-
 static char *lxcbasename(char *path)
 {
        char *p = path + strlen(path) - 1;
index 23b1b11ef43b5df5f9422ba2409037560276c1ea..93de1c3503fc6d3cfa93fbb0b84977b2b591845b 100644 (file)
@@ -1506,3 +1506,37 @@ int is_dir(const char *path)
                return 1;
        return 0;
 }
+
+/*
+ * Given the '-t' template option to lxc-create, figure out what to
+ * do.  If the template is a full executable path, use that.  If it
+ * is something like 'sshd', then return $templatepath/lxc-sshd.
+ * On success return the template, on error return NULL.
+ */
+char *get_template_path(const char *t)
+{
+       int ret, len;
+       char *tpath;
+
+       if (t[0] == '/' && access(t, X_OK) == 0) {
+               tpath = strdup(t);
+               return tpath;
+       }
+
+       len = strlen(LXCTEMPLATEDIR) + strlen(t) + strlen("/lxc-") + 1;
+       tpath = malloc(len);
+       if (!tpath)
+               return NULL;
+       ret = snprintf(tpath, len, "%s/lxc-%s", LXCTEMPLATEDIR, t);
+       if (ret < 0 || ret >= len) {
+               free(tpath);
+               return NULL;
+       }
+       if (access(tpath, X_OK) < 0) {
+               SYSERROR("bad template: %s", t);
+               free(tpath);
+               return NULL;
+       }
+
+       return tpath;
+}
index ae2c851e2c5152a3b04022aaea9bf9ede49ef186..b23cd8eeab80af85089e8bd17bdf7bad5ecc15b7 100644 (file)
@@ -285,3 +285,4 @@ char *choose_init(const char *rootfs);
 int print_to_file(const char *file, const char *content);
 bool switch_to_ns(pid_t pid, const char *ns);
 int is_dir(const char *path);
+char *get_template_path(const char *t);