> Use a duplicate of stdin and stdout fds to avoid closing the standard
> descriptors when the stdio chardev is destroyed.
> 
> Signed-off-by: Filip Hejsek <[email protected]>
> Message-ID: <[email protected]>
>
> diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c
> index fe1cbb2d880f..79092c4a7562 100644
> --- a/chardev/char-stdio.c
> +++ b/chardev/char-stdio.c
> @@ -108,7 +108,18 @@ static bool stdio_chr_open(Chardev *chr, ChardevBackend 
> *backend, Error **errp)
>          return false;
>      }
>  
> -    if (!qemu_chr_open_fd(chr, 0, 1, errp)) {
> +    int fd_in = qemu_dup(0);

QEMU style requires declarations at the beginning of blocks. Same applies to
fd_out below.

> +    if (fd_in < 0) {
> +        return false;

qemu_dup() can fail (EMFILE, EBADF). This returns false without setting *errp.
Should be:

    error_setg_errno(errp, errno, "Failed to dup stdin fd");

> +    }
> +    int fd_out = qemu_dup(1);
> +    if (fd_out < 0) {
> +        qemu_close(fd_in);
> +        return false;

Same

-- 
Marc-AndrĂ© Lureau <[email protected]>


Reply via email to