[lxc-devel] [PATCH] lxc_start: report error message when config is not a regular file
Yang Shi
yang.shi at linaro.org
Tue Oct 13 18:04:07 UTC 2015
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.
Exit with some error message to improve user experience.
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
More information about the lxc-devel
mailing list