]> 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>
Fri, 28 Aug 2015 22:02:15 +0000 (18:02 -0400)
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 d49704635ec9f347ed2b0d38250671738e11807a..60e5010032fc98f30d40178e9695f92f4896027b 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 8bd3d5c4825e15e5af456e2fa0470876dfdc7946..dfc255334996d3651932a3053fd6b6cae2c34256 100644 (file)
@@ -830,40 +830,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 abbec6c9d0cf7ac65f297918350152c2d1e8571e..2728edbebf0f50ccd94b5bb8a94b227a5aa43f71 100644 (file)
@@ -1322,3 +1322,37 @@ next_loop:
        free(path);
        return NULL;
 }
+
+/*
+ * 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 9bf6788058cf91479466aa80dd63e7e241c1c458..d15560c67bb1f18844409cf751ac4bf7f9038a6f 100644 (file)
@@ -279,4 +279,5 @@ uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval);
 int detect_shared_rootfs(void);
 int detect_ramfs_rootfs(void);
 char *on_path(char *cmd);
+char *get_template_path(const char *t);
 #endif /* __LXC_UTILS_H */