qemu_chr_write() dispatches to ChardevClass::chr_write(), and is expected to propagate the backend error, not some unrelated one produce by "best effort" logfile or replay. Preserve and return the relevant %errno.
Cc: [email protected] Reported-by: Peter Maydell <[email protected]> Reviewed-by: Marc-André Lureau <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> --- chardev/char.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/chardev/char.c b/chardev/char.c index 7931f4e0832..46a2dbfb5a3 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -114,6 +114,7 @@ static int qemu_chr_write_buffer(Chardev *s, int *offset, bool write_all) { ChardevClass *cc = CHARDEV_GET_CLASS(s); + int saved_errno; int res = 0; *offset = 0; @@ -139,6 +140,7 @@ static int qemu_chr_write_buffer(Chardev *s, break; } } + saved_errno = errno; if (*offset > 0) { /* * If some data was written by backend, we should @@ -156,6 +158,7 @@ static int qemu_chr_write_buffer(Chardev *s, qemu_chr_write_log(s, buf, len); } qemu_mutex_unlock(&s->chr_write_lock); + errno = saved_errno; return res; } @@ -192,7 +195,9 @@ int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all) } if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) { + int saved_errno = errno; replay_char_write_event_save(res, offset); + errno = saved_errno; } if (res < 0) { -- 2.51.0
