diff mbox

monitor: Cleanup mon->outbuf on write error

Message ID 1390818615-4926-1-git-send-email-psomas@grnet.gr
State New
Headers show

Commit Message

Stratos Psomadakis Jan. 27, 2014, 10:30 a.m. UTC
In case monitor_flush() fails to write the contents of mon->outbuf to
the output device, mon->outbuf is not cleaned up properly. Check the
return code of the qemu_chr_fe_write() function and cleanup the outbuf
if it fails.

References: http://lists.nongnu.org/archive/html/qemu-devel/2014-01/msg02890.html

Signed-off-by: Stratos Psomadakis <psomas@grnet.gr>
Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
---
 monitor.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Stratos Psomadakis Jan. 29, 2014, 10:46 a.m. UTC | #1
On 01/27/2014 12:30 PM, Stratos Psomadakis wrote:
> In case monitor_flush() fails to write the contents of mon->outbuf to
> the output device, mon->outbuf is not cleaned up properly. Check the
> return code of the qemu_chr_fe_write() function and cleanup the outbuf
> if it fails.
>
> References: http://lists.nongnu.org/archive/html/qemu-devel/2014-01/msg02890.html
>
> Signed-off-by: Stratos Psomadakis <psomas@grnet.gr>
> Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
> ---
>  monitor.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/monitor.c b/monitor.c
> index 80456fb..cba56bc 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -288,8 +288,8 @@ void monitor_flush(Monitor *mon)
>  
>      if (len && !mon->mux_out) {
>          rc = qemu_chr_fe_write(mon->chr, (const uint8_t *) buf, len);
> -        if (rc == len) {
> -            /* all flushed */
> +        if ((rc < 0 && errno != EAGAIN) || (rc == len)) {
> +            /* all flushed or error */
>              QDECREF(mon->outbuf);
>              mon->outbuf = qstring_new();
>              return;
 
Forgot to cc the maintainer.
Luiz Capitulino Jan. 29, 2014, 2:12 p.m. UTC | #2
On Wed, 29 Jan 2014 12:46:04 +0200
Stratos Psomadakis <psomas@grnet.gr> wrote:

> On 01/27/2014 12:30 PM, Stratos Psomadakis wrote:
> > In case monitor_flush() fails to write the contents of mon->outbuf to
> > the output device, mon->outbuf is not cleaned up properly. Check the
> > return code of the qemu_chr_fe_write() function and cleanup the outbuf
> > if it fails.
> >
> > References: http://lists.nongnu.org/archive/html/qemu-devel/2014-01/msg02890.html
> >
> > Signed-off-by: Stratos Psomadakis <psomas@grnet.gr>
> > Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
> > ---
> >  monitor.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/monitor.c b/monitor.c
> > index 80456fb..cba56bc 100644
> > --- a/monitor.c
> > +++ b/monitor.c
> > @@ -288,8 +288,8 @@ void monitor_flush(Monitor *mon)
> >  
> >      if (len && !mon->mux_out) {
> >          rc = qemu_chr_fe_write(mon->chr, (const uint8_t *) buf, len);
> > -        if (rc == len) {
> > -            /* all flushed */
> > +        if ((rc < 0 && errno != EAGAIN) || (rc == len)) {
> > +            /* all flushed or error */
> >              QDECREF(mon->outbuf);
> >              mon->outbuf = qstring_new();
> >              return;
>  
> Forgot to cc the maintainer.

I included it in my pull request:

http://lists.nongnu.org/archive/html/qemu-devel/2014-01/msg03859.html

But it seems that I forgot to reply to the patch too.
diff mbox

Patch

diff --git a/monitor.c b/monitor.c
index 80456fb..cba56bc 100644
--- a/monitor.c
+++ b/monitor.c
@@ -288,8 +288,8 @@  void monitor_flush(Monitor *mon)
 
     if (len && !mon->mux_out) {
         rc = qemu_chr_fe_write(mon->chr, (const uint8_t *) buf, len);
-        if (rc == len) {
-            /* all flushed */
+        if ((rc < 0 && errno != EAGAIN) || (rc == len)) {
+            /* all flushed or error */
             QDECREF(mon->outbuf);
             mon->outbuf = qstring_new();
             return;