Blob Blame History Raw
From 82ecce029a2e7d384b23f44c9c1c14b4ebbcbede Mon Sep 17 00:00:00 2001
From: Kouhei Sutou <kou@clear-code.com>
Date: Thu, 15 Jan 2015 21:53:16 +0900
Subject: [PATCH 3/4] gcut egg: fix a bug that source is removed twice

Signed-off-by: HAYASHI Kentaro <kenhys@gmail.com>
---
 gcutter/gcut-egg.c | 41 +++++++++++++++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/gcutter/gcut-egg.c b/gcutter/gcut-egg.c
index 83f0ed9..f4f0101 100644
--- a/gcutter/gcut-egg.c
+++ b/gcutter/gcut-egg.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
- *  Copyright (C) 2008-2011  Kouhei Sutou <kou@clear-code.com>
+ *  Copyright (C) 2008-2015  Kouhei Sutou <kou@clear-code.com>
  *
  *  This library is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU Lesser General Public License as published by
@@ -650,9 +650,8 @@ read_from_io_channel (GIOChannel *channel, GCutEgg *egg, guint signal)
 }
 
 static gboolean
-watch_output (GIOChannel *source, GIOCondition condition, gpointer user_data)
+watch_common (GIOChannel *source, GIOCondition condition, WatchOutputData *data)
 {
-    WatchOutputData *data = user_data;
     gboolean keep_callback = TRUE;
 
     if (condition & (G_IO_IN | G_IO_PRI)) {
@@ -678,6 +677,40 @@ watch_output (GIOChannel *source, GIOCondition condition, gpointer user_data)
     return keep_callback;
 }
 
+static gboolean
+watch_output (GIOChannel *source, GIOCondition condition, gpointer user_data)
+{
+    WatchOutputData *data = user_data;
+    gboolean keep_callback = TRUE;
+
+    keep_callback = watch_common(source, condition, user_data);
+
+    if (!keep_callback) {
+        GCutEggPrivate *priv;
+        priv = GCUT_EGG_GET_PRIVATE(data->egg);
+        priv->output_watch_id = 0;
+    }
+
+    return keep_callback;
+}
+
+static gboolean
+watch_error (GIOChannel *source, GIOCondition condition, gpointer user_data)
+{
+    WatchOutputData *data = user_data;
+    gboolean keep_callback = TRUE;
+
+    keep_callback = watch_common(source, condition, user_data);
+
+    if (!keep_callback) {
+        GCutEggPrivate *priv;
+        priv = GCUT_EGG_GET_PRIVATE(data->egg);
+        priv->error_watch_id = 0;
+    }
+
+    return keep_callback;
+}
+
 gboolean
 gcut_egg_hatch (GCutEgg *egg, GError **error)
 {
@@ -747,7 +780,7 @@ gcut_egg_hatch (GCutEgg *egg, GError **error)
         priv->watch_error_data->signal = signals[ERROR_RECEIVED];
         priv->error = create_input_channel(error_fd,
                                            &(priv->error_watch_id),
-                                           watch_output,
+                                           watch_error,
                                            priv->watch_error_data);
     }
 
-- 
2.1.0