From 92a5d12157a7286ec775bd47c6bde29ec63b91d1 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Mon, 12 Mar 2018 10:18:05 +0100 Subject: [PATCH] daemonStreamHandleWriteData: Preserve error when aborting stream The daemonStreamHandleWriteData() function is called whenever server side of stream is able to receive some data. Nevertheless, it calls virStreamSend() (to pass data down to virFDStream) and depending on its return value it may abort the stream. However, the functions it called when doing so are public APIs and as such reset any error set previously. Therefore, if there was any error in writing data to stream (i.e. repored in virStreamSend) it is reset before virNetServerProgramSendReplyError() can get to it. Signed-off-by: Michal Privoznik Reviewed-by: Andrea Bolognani --- src/remote/remote_daemon_stream.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/remote/remote_daemon_stream.c b/src/remote/remote_daemon_stream.c index 4dd3af9e0d..14472ced22 100644 --- a/src/remote/remote_daemon_stream.c +++ b/src/remote/remote_daemon_stream.c @@ -549,8 +549,9 @@ daemonStreamHandleWriteData(virNetServerClientPtr client, } else if (ret == -2) { /* Blocking, so indicate we have more todo later */ return 1; - } else { + } else if (ret < 0) { virNetMessageError rerr; + virErrorPtr err = virSaveLastError(); memset(&rerr, 0, sizeof(rerr)); @@ -559,6 +560,11 @@ daemonStreamHandleWriteData(virNetServerClientPtr client, virStreamEventRemoveCallback(stream->st); virStreamAbort(stream->st); + if (err) { + virSetError(err); + virFreeError(err); + } + return virNetServerProgramSendReplyError(stream->prog, client, msg,