From 18c8f05c2d9dd11070313d80fc9b0236dd35c000 Mon Sep 17 00:00:00 2001
From: mh17 <mh17>
Date: Mon, 7 Dec 2009 10:48:31 +0000
Subject: [PATCH] fixed hang up error on race condition on pipe stderr

---
 src/zmapServer/pipe/pipeServer.c   | 20 +++++++++++++-------
 src/zmapServer/pipe/pipeServer_P.h |  4 ++--
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/zmapServer/pipe/pipeServer.c b/src/zmapServer/pipe/pipeServer.c
index 71c0aed90..7cbfb4346 100755
--- a/src/zmapServer/pipe/pipeServer.c
+++ b/src/zmapServer/pipe/pipeServer.c
@@ -34,7 +34,7 @@
  * HISTORY:
  * Last edited: Nov 30 09:18 2009 (edgrif)
  * Created: 2009-11-26 12:02:40 (mh17)
- * CVS info:   $Id: pipeServer.c,v 1.5 2009-12-04 16:01:39 mh17 Exp $
+ * CVS info:   $Id: pipeServer.c,v 1.6 2009-12-07 10:48:31 mh17 Exp $
  *-------------------------------------------------------------------
  */
 
@@ -256,7 +256,8 @@ static gboolean pipe_server_spawn(PipeServer server,GError **error)
   if(result)
   {
     server->gff_pipe = g_io_channel_unix_new(pipe_fd);
-    server->gff_error = g_io_channel_unix_new(err_fd);
+    server->gff_stderr = g_io_channel_unix_new(err_fd);
+    g_io_channel_set_flags(server->gff_stderr,G_IO_FLAG_NONBLOCK,&pipe_error);
   }
 
   g_free(argv);   // strings allocated and freed seperately
@@ -288,12 +289,17 @@ gchar *pipe_server_get_stderr(PipeServer server)
   GError *gff_pipe_err = NULL;
   gchar * msg = NULL;
   GString *line;
-
+//  GIOCondition gc;
+  
   line = g_string_sized_new(2000) ;      /* Probably not many lines will be > 2k chars. */
 
   while (1)
     {
-      status = g_io_channel_read_line_string(server->gff_error, line,
+// this does'nt work: doesn't hang, but doesn't read the data anyway
+//      gc = g_io_channel_get_buffer_condition(server->gff_stderr);
+//      if(!(gc & G_IO_IN))
+//            break;
+      status = g_io_channel_read_line_string(server->gff_stderr, line,
             &terminator_pos,&gff_pipe_err);
       if(status != G_IO_STATUS_NORMAL)
         break;
@@ -804,7 +810,7 @@ static ZMapServerResponseType closeConnection(void *server_in)
       server->gff_pipe = NULL ;
     }
 
-  if (server->gff_error && g_io_channel_shutdown(server->gff_error, FALSE, &gff_pipe_err) != G_IO_STATUS_NORMAL)
+  if (server->gff_stderr && g_io_channel_shutdown(server->gff_stderr, FALSE, &gff_pipe_err) != G_IO_STATUS_NORMAL)
     {
       zMapLogCritical("Could not close error pipe \"%s\"", server->script_path) ;
 
@@ -815,8 +821,8 @@ static ZMapServerResponseType closeConnection(void *server_in)
   else
     {
       /* this seems to be required to destroy the GIOChannel.... */
-      g_io_channel_unref(server->gff_error) ;
-      server->gff_error = NULL ;
+      g_io_channel_unref(server->gff_stderr) ;
+      server->gff_stderr = NULL ;
     }
 
   return result ;
diff --git a/src/zmapServer/pipe/pipeServer_P.h b/src/zmapServer/pipe/pipeServer_P.h
index 60f5c2ae2..29abbe5a8 100755
--- a/src/zmapServer/pipe/pipeServer_P.h
+++ b/src/zmapServer/pipe/pipeServer_P.h
@@ -28,7 +28,7 @@
  *              
  * HISTORY:
  * Created: Thu Nov 26 10:30:21 2009 (mh17)
- * CVS info:   $Id: pipeServer_P.h,v 1.3 2009-12-04 16:01:39 mh17 Exp $
+ * CVS info:   $Id: pipeServer_P.h,v 1.4 2009-12-07 10:48:31 mh17 Exp $
  *-------------------------------------------------------------------
  */
 #ifndef PIPE_SERVER_P_H
@@ -51,7 +51,7 @@ typedef struct _PipeServerStruct
   gchar *script_path ;	      // where our configured script is, includign script-dir
   gchar *query;		    	// from query string
   GIOChannel *gff_pipe ;      // the pipe we read the script's output from
-  GIOChannel *gff_error ;     // the pipe we read the script's error output from
+  GIOChannel *gff_stderr ;    // the pipe we read the script's error output from
   GPid child_pid;
   gint zmap_start,zmap_end;   // display coordinates of interesting region
   gint wait;                  // delay before gettign data, mainly for testing
-- 
GitLab