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