[lxc-devel] [lxc/master] tools: better error reporting for lxc-start

brauner on Github lxc-bot at linuxcontainers.org
Fri Oct 14 13:29:01 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 437 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161014/ba7f4b60/attachment.bin>
-------------- next part --------------
From 1702996ab9f52b453f18ef344597b02fb9415074 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at canonical.com>
Date: Fri, 14 Oct 2016 15:27:24 +0200
Subject: [PATCH] tools: better error reporting for lxc-start

Signed-off-by: Christian Brauner <christian.brauner at canonical.com>
---
 src/lxc/tools/lxc_start.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/lxc/tools/lxc_start.c b/src/lxc/tools/lxc_start.c
index 25d8f19..32a78c4 100644
--- a/src/lxc/tools/lxc_start.c
+++ b/src/lxc/tools/lxc_start.c
@@ -86,7 +86,7 @@ static int ensure_path(char **confpath, const char *path)
 			goto err;
 		}
 	}
-	err = 0;
+	err = EXIT_SUCCESS;
 
 err:
 	free(fullpath);
@@ -231,6 +231,14 @@ int main(int argc, char *argv[])
 		exit(err);
 	lxc_log_options_no_override();
 
+	if (geteuid()) {
+		if (access(my_args.lxcpath[0], O_RDWR) < 0) {
+			if (!my_args.quiet)
+				fprintf(stderr, "You lack access to %s\n", my_args.lxcpath[0]);
+			exit(err);
+		}
+	}
+
 	const char *lxcpath = my_args.lxcpath[0];
 
 	/*
@@ -275,9 +283,19 @@ int main(int argc, char *argv[])
 		}
 	}
 
+	if (!c->may_control(c)) {
+		fprintf(stderr, "Insufficent privileges to control %s\n", c->name);
+		goto out;
+	}
+
+	if (!c->is_defined(c)) {
+		fprintf(stderr, "Error: container %s is not defined\n", c->name);
+		goto out;
+	}
+
 	if (c->is_running(c)) {
 		ERROR("Container is already running.");
-		err = 0;
+		err = EXIT_SUCCESS;
 		goto out;
 	}
 	/*


More information about the lxc-devel mailing list