dm: uart: use mevent_add only when it is a tty
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.
Acked-by: Yu Wang
@@ -790,11 +790,13 @@ uart_reset_backend(struct uart_backend *be)
break;
}
+ if (evp) {
error = mevent_enable(evp);
if (error) {
WPRINTF(("mevent_enable error\n"));
return -1;
}
+ }
return 0;
}
@@ -821,6 +823,7 @@ uart_enable_backend(struct uart_backend *be, bool enable)
return -1;
}
+ if (evp) {
if (enable)
error = mevent_enable(evp);
else
@@ -829,6 +832,7 @@ uart_enable_backend(struct uart_backend *be, bool enable)
WPRINTF(("mevent %s error\n", enable ? "enable" : "disable"));
return -1;
}
+ }
return 0;
}
@@ -909,12 +913,19 @@ uart_config_backend(struct uart_vdev *uart, struct uart_backend *be, long port)
atexit(uart_reset_stdio);
}
be->opened = true;
+ /*
+ * When acrn-dm is started by acrnd as a background process,
+ * STDIO is redirected to journal log file. In this case epoll
+ * cannot be used on a regular file.
+ */
+ if (isatty(fd)) {
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:
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&opt,
