[balsa] Handle broken pipe and other errors before writing



commit c12c6c3fcb02725fdd10683f7af25bbf62cd42ac
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Jun 28 16:00:16 2017 -0400

    Handle broken pipe and other errors before writing
    
        * src/balsa-index.c (pipe_in_watch): handle G_IO_HUP or G_IO_ERR
        and return, before writing to the pipe.

 ChangeLog         |    7 +++++++
 src/balsa-index.c |   21 ++++++++++++---------
 2 files changed, 19 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a217e1e..e1749b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2017-06-28  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       Handle broken pipe and other errors before writing to pipe
+
+       * src/balsa-index.c (pipe_in_watch): handle G_IO_HUP or G_IO_ERR
+       and return, before writing to the pipe.
+
 2017-06-26  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Remove dead assignment
diff --git a/src/balsa-index.c b/src/balsa-index.c
index fd15180..137436a 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -2317,6 +2317,17 @@ pipe_in_watch(GIOChannel *channel, GIOCondition condition, gpointer data)
     gsize chars_written;
     gboolean rc;
 
+    if ((condition & (G_IO_HUP | G_IO_ERR)) != 0) {
+        if ((condition & G_IO_HUP) != 0) {
+            fprintf(stderr, "pipe_in_watch: broken pipe. Aborts writing.\n");
+        }
+        if ((condition & G_IO_ERR) != 0) {
+            fprintf(stderr, "pipe_in_watch encountered error. Aborts writing.\n");
+        }
+       pipe_data_destroy(pipe);
+        return FALSE;
+    }
+
     if( (condition & G_IO_OUT) == G_IO_OUT) {
        status =
            g_io_channel_write_chars(channel,
@@ -2346,15 +2357,7 @@ pipe_in_watch(GIOChannel *channel, GIOCondition condition, gpointer data)
            break;
        }
     }
-    if( (condition & G_IO_HUP) == G_IO_HUP) {
-       pipe_data_destroy(pipe);
-       rc = FALSE;
-    }
-    if( (condition & G_IO_ERR) == G_IO_ERR) {
-       fprintf(stderr,
-               "pipe_in_watch encountered error. Aborts writing.\n");
-       return FALSE;
-    }
+
     rc = pipe->message_length > pipe->chars_written;
     if(!rc) {
        g_io_channel_unref(pipe->in_channel); pipe->in_channel = NULL;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]