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