[lxc-devel] [PATCH] lxc_start: report error message when config is not a regular file
Serge Hallyn
serge.hallyn at ubuntu.com
Thu Oct 15 14:31:00 UTC 2015
Quoting Yang Shi (yang.shi at linaro.org):
> When run the below command:
> lxc-start -n name -f /path/to/config
>
> If config is not a regular file, lxc-start will be killed by SEG FAULT
> directly.
What exactly was the file to get a segfault? When I try with a device
or a directory I do not get a segfault.
> Exit with some error message to improve user experience.
This is not the place to put that check (if it is needed). It should go
into either lxc_container_new or load_config, wherever it is failing.
> Signed-off-by: Yang Shi <yang.shi at linaro.org>
> ---
> src/lxc/lxc_start.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
> index 6b942ac..d1cf779 100644
> --- a/src/lxc/lxc_start.c
> +++ b/src/lxc/lxc_start.c
> @@ -212,6 +212,7 @@ int main(int argc, char *argv[])
> NULL,
> };
> struct lxc_container *c;
> + struct stat st_stat = {0};
>
> lxc_list_init(&defines);
>
> @@ -242,6 +243,18 @@ int main(int argc, char *argv[])
> /* rcfile is specified in the cli option */
> if (my_args.rcfile) {
> rcfile = (char *)my_args.rcfile;
> + tmp = stat(rcfile, &st_stat);
> +
> + if (tmp && errno == ENOENT) {
> + ERROR("The config path doesn't exist.\n");
> + return err;
> + }
> +
> + if (!tmp && !S_ISREG(st_stat.st_mode)) {
> + ERROR("The config is not a regular file.\n");
> + return err;
> + }
> +
> c = lxc_container_new(my_args.name, lxcpath);
> if (!c) {
> ERROR("Failed to create lxc_container");
> --
> 2.0.2
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
More information about the lxc-devel
mailing list