dm: uart: fix acrn-dm crash issue when invoke uart_closetty function

mevent is added only if uart backend fd refers TTY in uart_opentty.
So we should only delete mevent if uart backend fd refers TTY in uart_closetty.

This issue can be reproduced by below steps
1) acrnd starts UOS
2) run poweroff command in UOS
3) crash happens

Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
This commit is contained in:
Yuan Liu 2018-08-02 17:43:07 +08:00 committed by lijinxia
parent 8f39a22961
commit 7a3d03c82d

View File

@ -275,12 +275,15 @@ uart_opentty(struct uart_vdev *uart)
static void
uart_closetty(struct uart_vdev *uart)
{
if (uart->tty.fd != STDIN_FILENO)
mevent_delete_close(uart->mev);
else
mevent_delete(uart->mev);
if (isatty(uart->tty.fd)) {
if (uart->tty.fd != STDIN_FILENO)
mevent_delete_close(uart->mev);
else
mevent_delete(uart->mev);
uart->mev = 0;
}
uart->mev = 0;
ttyclose();
}