Index: docs/reference/glib/glib-sections.txt
===================================================================
--- docs/reference/glib/glib-sections.txt	(revision 7129)
+++ docs/reference/glib/glib-sections.txt	(working copy)
@@ -757,6 +757,8 @@
 g_io_create_watch
 g_io_add_watch
 g_io_add_watch_full
+g_io_watch_set_ignore_read_buffer
+g_io_watch_get_ignore_read_buffer
 GIOCondition
 GIOFunc
 
Index: glib/gmain.c
===================================================================
--- glib/gmain.c	(revision 7129)
+++ glib/gmain.c	(working copy)
@@ -107,7 +107,8 @@
 typedef enum
 {
   G_SOURCE_READY = 1 << G_HOOK_FLAG_USER_SHIFT,
-  G_SOURCE_CAN_RECURSE = 1 << (G_HOOK_FLAG_USER_SHIFT + 1)
+  G_SOURCE_CAN_RECURSE = 1 << (G_HOOK_FLAG_USER_SHIFT + 1),
+  G_SOURCE_IGNORE_READ_BUFFER = 1 << (G_HOOK_FLAG_USER_SHIFT + 2)
 } GSourceFlags;
 
 #ifdef G_THREADS_ENABLED
@@ -1382,6 +1383,65 @@
 }
 
 /**
+ * g_io_watch_set_ignore_read_buffer:
+ * @source: a #GSource returned by g_io_create_watch()
+ * @ignore_read_buffer: whether this watch should ignore the read buffer
+ * 
+ * Sets a flag determining whether the watch represented by @source currently
+ * ignores its channel's read buffer.  When this flag is off (the default),
+ * condition %G_IO_IN can be met by data in the read buffer or data available
+ * from the underlying file descriptor (or socket, etc.).  When it is on,
+ * %G_IO_IN will not occur until new data arrives at the underlying file
+ * descriptor, and the flag is automatically turned off when that happens.
+ * 
+ * The ignore-read-buffer flag was added to make it possible to read lines from
+ * a channel using g_io_channel_read_line() or similar without blocking other
+ * activity or entering a busy loop.  To do this, set %G_IO_FLAG_NONBLOCK on
+ * the channel, and have the #GIOFunc enable the ignore-read-buffer flag when
+ * it gets %G_IO_STATUS_AGAIN.  See GNOME bug 126266.
+ * 
+ * This flag is currently implemented only on Unix.
+ **/
+void
+g_io_watch_set_ignore_read_buffer (GSource  *source,
+                                   gboolean  ignore_read_buffer)
+{
+  GMainContext *context;
+  
+  g_return_if_fail (source != NULL);
+
+  context = source->context;
+
+  if (context)
+    LOCK_CONTEXT (context);
+  
+  if (ignore_read_buffer)
+    source->flags |= G_SOURCE_IGNORE_READ_BUFFER;
+  else
+    source->flags &= ~G_SOURCE_IGNORE_READ_BUFFER;
+
+  if (context)
+    UNLOCK_CONTEXT (context);
+}
+
+/**
+ * g_io_watch_get_ignore_read_buffer:
+ * @source: a #GSource returned by g_io_create_watch()
+ * 
+ * Checks whether a watch is currently ignoring the read buffer.
+ * See g_io_watch_set_ignore_read_buffer().
+ * 
+ * Return value: whether this watch currently ignores the read buffer.
+ **/
+gboolean
+g_io_watch_get_ignore_read_buffer (GSource  *source)
+{
+  g_return_val_if_fail (source != NULL, FALSE);
+  
+  return (source->flags & G_SOURCE_IGNORE_READ_BUFFER) != 0;
+}
+
+/**
  * g_source_ref:
  * @source: a #GSource
  * 
Index: glib/giochannel.h
===================================================================
--- glib/giochannel.h	(revision 7129)
+++ glib/giochannel.h	(working copy)
@@ -200,6 +200,9 @@
 				 GIOCondition     condition,
 				 GIOFunc          func,
 				 gpointer         user_data);
+void     g_io_watch_set_ignore_read_buffer (GSource *source,
+					    gboolean ignore_read_buffer);
+gboolean g_io_watch_get_ignore_read_buffer (GSource *source);
 
 /* character encoding conversion involved functions.
  */
Index: glib/giounix.c
===================================================================
--- glib/giounix.c	(revision 7129)
+++ glib/giounix.c	(working copy)
@@ -118,12 +118,21 @@
   g_io_unix_get_flags,
 };
 
+static GIOCondition
+g_io_unix_watch_buffer_condition (GIOUnixWatch *watch)
+{
+  GIOCondition buffer_condition = g_io_channel_get_buffer_condition (watch->channel);
+  if (g_io_watch_get_ignore_read_buffer ((GSource *) watch))
+    buffer_condition &= ~G_IO_IN;
+  return buffer_condition;
+}
+
 static gboolean 
 g_io_unix_prepare (GSource  *source,
 		   gint     *timeout)
 {
   GIOUnixWatch *watch = (GIOUnixWatch *)source;
-  GIOCondition buffer_condition = g_io_channel_get_buffer_condition (watch->channel);
+  GIOCondition buffer_condition = g_io_unix_watch_buffer_condition (watch);
 
   *timeout = -1;
 
@@ -136,8 +145,10 @@
 g_io_unix_check (GSource  *source)
 {
   GIOUnixWatch *watch = (GIOUnixWatch *)source;
-  GIOCondition buffer_condition = g_io_channel_get_buffer_condition (watch->channel);
   GIOCondition poll_condition = watch->pollfd.revents;
+  if (poll_condition & G_IO_IN)
+    g_io_watch_set_ignore_read_buffer ((GSource *) watch, FALSE);
+  GIOCondition buffer_condition = g_io_unix_watch_buffer_condition (watch);
 
   return ((poll_condition | buffer_condition) & watch->condition);
 }
@@ -150,7 +161,7 @@
 {
   GIOFunc func = (GIOFunc)callback;
   GIOUnixWatch *watch = (GIOUnixWatch *)source;
-  GIOCondition buffer_condition = g_io_channel_get_buffer_condition (watch->channel);
+  GIOCondition buffer_condition = g_io_unix_watch_buffer_condition (watch);
 
   if (!func)
     {
