The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/2816
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === When calling lxc-create, if the template exists but is not executable, we end with the following error messages which make believe that the template file does not exist when it is merely a execute access problem: lxc-create: ctn00: utils.c: get_template_path: 918 No such file or directory - bad template: /.../lxc-busybox lxc-create: ctn00: lxccontainer.c: do_lxcapi_create: 1786 Unknown template "/.../lxc-busybox" lxc-create: ctn00: tools/lxc_create.c: main: 327 Failed to create container ctn00 Moreover, internally this triggers a useless access to (strace output): access("/.../lxc-busybox", X_OK) = -1 ENOENT (No such file or directory) With the above fix, we get a more explicit error message when the template file is missing the "execute" bit: lxc-create: ctn: utils.c: get_template_path: 926 Permission denied - cannot execute template /h.../lxc-busybox lxc-create: ctn: lxccontainer.c: do_lxcapi_create: 1816 Unknown template "/.../lxc-busybox" lxc-create: ctn: tools/lxc_create.c: main: 331 Failed to create container ctn With the above fix, we get a more explicit error message when the pathname of the template file is incorrect: lxc-create: ctn: utils.c: get_template_path: 931 No such file or directory - template /.../lxc-busybox does not exist lxc-create: ctn: lxccontainer.c: do_lxcapi_create: 1816 Unknown template "/.../lxc-busybox" lxc-create: ctn: tools/lxc_create.c: main: 331 Failed to create container ctn Signed-off-by: Rachid Koucha <rachid.kou...@gmail.com>
From 75743d5631c604dcb4ef540cb2684bafa386dbed Mon Sep 17 00:00:00 2001 From: Rachid Koucha <47061324+rachid-kou...@users.noreply.github.com> Date: Tue, 29 Jan 2019 09:46:34 +0100 Subject: [PATCH] More accurate error msg for template file When calling lxc-create, if the template exists but is not executable, we end with the following error messages which make believe that the template file does not exist when it is merely a execute access problem: lxc-create: ctn00: utils.c: get_template_path: 918 No such file or directory - bad template: /.../lxc-busybox lxc-create: ctn00: lxccontainer.c: do_lxcapi_create: 1786 Unknown template "/.../lxc-busybox" lxc-create: ctn00: tools/lxc_create.c: main: 327 Failed to create container ctn00 Moreover, internally this triggers a useless access to (strace output): access("/.../lxc-busybox", X_OK) = -1 ENOENT (No such file or directory) With the above fix, we get a more explicit error message when the template file is missing the "execute" bit: lxc-create: ctn: utils.c: get_template_path: 926 Permission denied - cannot execute template /h.../lxc-busybox lxc-create: ctn: lxccontainer.c: do_lxcapi_create: 1816 Unknown template "/.../lxc-busybox" lxc-create: ctn: tools/lxc_create.c: main: 331 Failed to create container ctn With the above fix, we get a more explicit error message when the pathname of the template file is incorrect: lxc-create: ctn: utils.c: get_template_path: 931 No such file or directory - template /.../lxc-busybox does not exist lxc-create: ctn: lxccontainer.c: do_lxcapi_create: 1816 Unknown template "/.../lxc-busybox" lxc-create: ctn: tools/lxc_create.c: main: 331 Failed to create container ctn Signed-off-by: Rachid Koucha <rachid.kou...@gmail.com> --- src/lxc/utils.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/lxc/utils.c b/src/lxc/utils.c index f3e262280..49e2d79b7 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -910,9 +910,24 @@ 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; + if (t[0] == '/') { + if (access(t, X_OK) == 0) { + tpath = strdup(t); + return tpath; + } else { + if (errno == EACCES) { + SYSERROR("cannot execute template %s", t); + return NULL; + } + + if (errno == ENOENT) { + SYSERROR("template %s does not exist", t); + return NULL; + } + + SYSERROR("Bad template pathname: %s", t); + return NULL; + } } len = strlen(LXCTEMPLATEDIR) + strlen(t) + strlen("/lxc-") + 1;
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel