[lxc-devel] [lxc/master] tools: only check for O_RDONLY

brauner on Github lxc-bot at linuxcontainers.org
Wed Jan 4 15:30:34 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 584 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170104/61462e38/attachment.bin>
-------------- next part --------------
From 371802081a23d66f657dec0ccc00659f7b8263dd Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 4 Jan 2017 16:28:50 +0100
Subject: [PATCH] tools: only check for O_RDONLY

On some Android systems the lxc folders where containers are stored might be
read-only and so checking for O_RDWR, will effectively make the tools useless
on these systems, so let's dumb the check down to O_RDONLY.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/tools/lxc_attach.c   | 2 +-
 src/lxc/tools/lxc_copy.c     | 2 +-
 src/lxc/tools/lxc_create.c   | 2 +-
 src/lxc/tools/lxc_snapshot.c | 2 +-
 src/lxc/tools/lxc_start.c    | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/lxc/tools/lxc_attach.c b/src/lxc/tools/lxc_attach.c
index 4dd3883..01e505a 100644
--- a/src/lxc/tools/lxc_attach.c
+++ b/src/lxc/tools/lxc_attach.c
@@ -395,7 +395,7 @@ int main(int argc, char *argv[])
 	lxc_log_options_no_override();
 
 	if (geteuid()) {
-		if (access(my_args.lxcpath[0], O_RDWR) < 0) {
+		if (access(my_args.lxcpath[0], O_RDONLY) < 0) {
 			if (!my_args.quiet)
 				fprintf(stderr, "You lack access to %s\n", my_args.lxcpath[0]);
 			exit(EXIT_FAILURE);
diff --git a/src/lxc/tools/lxc_copy.c b/src/lxc/tools/lxc_copy.c
index 4d0c17d..0627a62 100644
--- a/src/lxc/tools/lxc_copy.c
+++ b/src/lxc/tools/lxc_copy.c
@@ -184,7 +184,7 @@ int main(int argc, char *argv[])
 	lxc_log_options_no_override();
 
 	if (geteuid()) {
-		if (access(my_args.lxcpath[0], O_RDWR) < 0) {
+		if (access(my_args.lxcpath[0], O_RDONLY) < 0) {
 			if (!my_args.quiet)
 				fprintf(stderr, "You lack access to %s\n", my_args.lxcpath[0]);
 			exit(ret);
diff --git a/src/lxc/tools/lxc_create.c b/src/lxc/tools/lxc_create.c
index 6e8acf0..b8795c4 100644
--- a/src/lxc/tools/lxc_create.c
+++ b/src/lxc/tools/lxc_create.c
@@ -252,7 +252,7 @@ int main(int argc, char *argv[])
 		if (mkdir_p(my_args.lxcpath[0], 0755)) {
 			exit(EXIT_FAILURE);
 		}
-		if (access(my_args.lxcpath[0], O_RDWR) < 0) {
+		if (access(my_args.lxcpath[0], O_RDONLY) < 0) {
 			fprintf(stderr, "You lack access to %s\n", my_args.lxcpath[0]);
 			exit(EXIT_FAILURE);
 		}
diff --git a/src/lxc/tools/lxc_snapshot.c b/src/lxc/tools/lxc_snapshot.c
index 1a79a7a..6948d19 100644
--- a/src/lxc/tools/lxc_snapshot.c
+++ b/src/lxc/tools/lxc_snapshot.c
@@ -95,7 +95,7 @@ int main(int argc, char *argv[])
 	lxc_log_options_no_override();
 
 	if (geteuid()) {
-		if (access(my_args.lxcpath[0], O_RDWR) < 0) {
+		if (access(my_args.lxcpath[0], O_RDONLY) < 0) {
 			fprintf(stderr, "You lack access to %s\n",
 				my_args.lxcpath[0]);
 			exit(EXIT_FAILURE);
diff --git a/src/lxc/tools/lxc_start.c b/src/lxc/tools/lxc_start.c
index c85305b..f5aa24b 100644
--- a/src/lxc/tools/lxc_start.c
+++ b/src/lxc/tools/lxc_start.c
@@ -231,7 +231,7 @@ int main(int argc, char *argv[])
 		exit(err);
 	lxc_log_options_no_override();
 
-	if (access(my_args.lxcpath[0], O_RDWR) < 0) {
+	if (access(my_args.lxcpath[0], O_RDONLY) < 0) {
 		if (!my_args.quiet)
 			fprintf(stderr, "You lack access to %s\n", my_args.lxcpath[0]);
 		exit(err);


More information about the lxc-devel mailing list