Re: [PATCH] dm: uart: use mevent_add only when it is a tty


Yu Wang
 

On 19-04-23 10:26:22, Jian Jun Chen wrote:
When acrn-dm is started by acrnd as a background process, STDIN is
redirected to journal. In this case mevent_add cannot be called on
the fd of STDIN.

Tracked-On: #2998
Signed-off-by: Jian Jun Chen <jian.jun.chen@...>
---
devicemodel/hw/uart_core.c | 38 ++++++++++++++++++++++----------------
1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/devicemodel/hw/uart_core.c b/devicemodel/hw/uart_core.c
index 72e5a6f8..a26f2c6c 100644
--- a/devicemodel/hw/uart_core.c
+++ b/devicemodel/hw/uart_core.c
@@ -790,10 +790,12 @@ uart_reset_backend(struct uart_backend *be)
break;
}

- error = mevent_enable(evp);
- if (error) {
- WPRINTF(("mevent_enable error\n"));
- return -1;
+ if (evp) {
+ error = mevent_enable(evp);
+ if (error) {
+ WPRINTF(("mevent_enable error\n"));
+ return -1;
+ }
}

return 0;
@@ -821,13 +823,15 @@ uart_enable_backend(struct uart_backend *be, bool enable)
return -1;
}

- if (enable)
- error = mevent_enable(evp);
- else
- error = mevent_disable(evp);
- if (error) {
- WPRINTF(("mevent %s error\n", enable ? "enable" : "disable"));
- return -1;
+ if (evp) {
+ if (enable)
+ error = mevent_enable(evp);
+ else
+ error = mevent_disable(evp);
+ if (error) {
+ WPRINTF(("mevent %s error\n", enable ? "enable" : "disable"));
+ return -1;
+ }
}

return 0;
@@ -909,11 +913,13 @@ uart_config_backend(struct uart_vdev *uart, struct uart_backend *be, long port)
atexit(uart_reset_stdio);
}
be->opened = true;
- be->evp = mevent_add(fd, EVF_READ, uart_drain, uart,
- uart_mevent_teardown, uart);
- if (!be->evp) {
- WPRINTF(("uart: mevent_add failed\n"));
- return -1;
+ if (isatty(fd)) {
Please add some comment in there to clarify the acrnd case.
Others are looks good to me.

Acked-by: Yu Wang <yu1.wang@...>
+ be->evp = mevent_add(fd, EVF_READ, uart_drain, uart,
+ uart_mevent_teardown, uart);
+ if (!be->evp) {
+ WPRINTF(("uart: mevent_add failed\n"));
+ return -1;
+ }
}
break;
case UART_BE_SOCK:
--
2.19.1

Join acrn-dev@lists.projectacrn.org to automatically receive all group messages.