1From f512071dd3a4c29d4bf048c5a89c4ba9160e37b1 Mon Sep 17 00:00:00 2001
2From: Chen Qi <Qi.Chen@windriver.com>
3Date: Thu, 17 Jul 2014 15:53:34 +0800
4Subject: [PATCH] commonio.c-fix-unexpected-open-failure-in-chroot-env
5
6Upstream-Status: Inappropriate [OE specific]
7
8commonio.c: fix unexpected open failure in chroot environment
9
10When using commands with '-R <newroot>' option in our pseudo environment,
11we would usually get the 'Pemission Denied' error. This patch serves as
12a workaround to this problem.
13
14Note that this patch doesn't change the logic in the code, it just expands
15the codes.
16
17Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
18---
19 lib/commonio.c | 16 ++++++++++++----
20 1 file changed, 12 insertions(+), 4 deletions(-)
21
22diff --git a/lib/commonio.c b/lib/commonio.c
23index 01a26c9..82b2868 100644
24--- a/lib/commonio.c
25+++ b/lib/commonio.c
26@@ -601,10 +601,18 @@ int commonio_open (struct commonio_db *db, int mode)
27 	db->cursor = NULL;
28 	db->changed = false;
29
30-	fd = open (db->filename,
31-	             (db->readonly ? O_RDONLY : O_RDWR)
32-	           | O_NOCTTY | O_NONBLOCK | O_NOFOLLOW | O_CLOEXEC);
33-	saved_errno = errno;
34+	if (db->readonly) {
35+		fd = open (db->filename,
36+			   (true ? O_RDONLY : O_RDWR)
37+			   | O_NOCTTY | O_NONBLOCK | O_NOFOLLOW | O_CLOEXEC);
38+		saved_errno = errno;
39+	} else {
40+		fd = open (db->filename,
41+			   (false ? O_RDONLY : O_RDWR)
42+			   | O_NOCTTY | O_NONBLOCK | O_NOFOLLOW| O_CLOEXEC);
43+		saved_errno = errno;
44+	}
45+
46 	db->fp = NULL;
47 	if (fd >= 0) {
48 #ifdef WITH_TCB
49