Fix double close of file descriptor on error. (#82139, Wayne Schuller)
authorOwen Taylor <otaylor@redhat.com>
Mon, 20 May 2002 19:36:58 +0000 (19:36 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Mon, 20 May 2002 19:36:58 +0000 (19:36 +0000)
Mon May 20 15:35:59 2002  Owen Taylor  <otaylor@redhat.com>

        * glib/gfileutils.c (get_contents_regfile): Fix double
        close of file descriptor on error. (#82139, Wayne Schuller)

        * glib/gspawn.c (close_and_invalidate): Don't close
        fd's that have already been closed. (Fix from Michael
        Meeks, #81959)

        * glib/giochannel.c (g_io_channel_close): If not flushing,
        dump the contents of the write buffers, so we won't try
        to write them to an invalid fd later. (Patch from Ron Steinke,
        fixing #78290, Andreas Persenius.)

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gfileutils.c
glib/giochannel.c
glib/gspawn.c

index 311a2c7..9154a4e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Mon May 20 15:35:59 2002  Owen Taylor  <otaylor@redhat.com>
+       * glib/gfileutils.c (get_contents_regfile): Fix double
+       close of file descriptor on error. (#82139, Wayne Schuller)
+       * glib/gspawn.c (close_and_invalidate): Don't close
+       fd's that have already been closed. (Fix from Michael
+       Meeks, #81959)
+       * glib/giochannel.c (g_io_channel_close): If not flushing,
+       dump the contents of the write buffers, so we won't try
+       to write them to an invalid fd later. (Patch from Ron Steinke,
+       fixing #78290, Andreas Persenius.)
 2002-05-18  Matthias Clasen  <maclas@gmx.de>
 
        * tests/markups/fail-36.gmarkup: 
index 311a2c7..9154a4e 100644 (file)
@@ -1,3 +1,17 @@
+Mon May 20 15:35:59 2002  Owen Taylor  <otaylor@redhat.com>
+       * glib/gfileutils.c (get_contents_regfile): Fix double
+       close of file descriptor on error. (#82139, Wayne Schuller)
+       * glib/gspawn.c (close_and_invalidate): Don't close
+       fd's that have already been closed. (Fix from Michael
+       Meeks, #81959)
+       * glib/giochannel.c (g_io_channel_close): If not flushing,
+       dump the contents of the write buffers, so we won't try
+       to write them to an invalid fd later. (Patch from Ron Steinke,
+       fixing #78290, Andreas Persenius.)
 2002-05-18  Matthias Clasen  <maclas@gmx.de>
 
        * tests/markups/fail-36.gmarkup: 
index 311a2c7..9154a4e 100644 (file)
@@ -1,3 +1,17 @@
+Mon May 20 15:35:59 2002  Owen Taylor  <otaylor@redhat.com>
+       * glib/gfileutils.c (get_contents_regfile): Fix double
+       close of file descriptor on error. (#82139, Wayne Schuller)
+       * glib/gspawn.c (close_and_invalidate): Don't close
+       fd's that have already been closed. (Fix from Michael
+       Meeks, #81959)
+       * glib/giochannel.c (g_io_channel_close): If not flushing,
+       dump the contents of the write buffers, so we won't try
+       to write them to an invalid fd later. (Patch from Ron Steinke,
+       fixing #78290, Andreas Persenius.)
 2002-05-18  Matthias Clasen  <maclas@gmx.de>
 
        * tests/markups/fail-36.gmarkup: 
index 311a2c7..9154a4e 100644 (file)
@@ -1,3 +1,17 @@
+Mon May 20 15:35:59 2002  Owen Taylor  <otaylor@redhat.com>
+       * glib/gfileutils.c (get_contents_regfile): Fix double
+       close of file descriptor on error. (#82139, Wayne Schuller)
+       * glib/gspawn.c (close_and_invalidate): Don't close
+       fd's that have already been closed. (Fix from Michael
+       Meeks, #81959)
+       * glib/giochannel.c (g_io_channel_close): If not flushing,
+       dump the contents of the write buffers, so we won't try
+       to write them to an invalid fd later. (Patch from Ron Steinke,
+       fixing #78290, Andreas Persenius.)
 2002-05-18  Matthias Clasen  <maclas@gmx.de>
 
        * tests/markups/fail-36.gmarkup: 
index 311a2c7..9154a4e 100644 (file)
@@ -1,3 +1,17 @@
+Mon May 20 15:35:59 2002  Owen Taylor  <otaylor@redhat.com>
+       * glib/gfileutils.c (get_contents_regfile): Fix double
+       close of file descriptor on error. (#82139, Wayne Schuller)
+       * glib/gspawn.c (close_and_invalidate): Don't close
+       fd's that have already been closed. (Fix from Michael
+       Meeks, #81959)
+       * glib/giochannel.c (g_io_channel_close): If not flushing,
+       dump the contents of the write buffers, so we won't try
+       to write them to an invalid fd later. (Patch from Ron Steinke,
+       fixing #78290, Andreas Persenius.)
 2002-05-18  Matthias Clasen  <maclas@gmx.de>
 
        * tests/markups/fail-36.gmarkup: 
index 311a2c7..9154a4e 100644 (file)
@@ -1,3 +1,17 @@
+Mon May 20 15:35:59 2002  Owen Taylor  <otaylor@redhat.com>
+       * glib/gfileutils.c (get_contents_regfile): Fix double
+       close of file descriptor on error. (#82139, Wayne Schuller)
+       * glib/gspawn.c (close_and_invalidate): Don't close
+       fd's that have already been closed. (Fix from Michael
+       Meeks, #81959)
+       * glib/giochannel.c (g_io_channel_close): If not flushing,
+       dump the contents of the write buffers, so we won't try
+       to write them to an invalid fd later. (Patch from Ron Steinke,
+       fixing #78290, Andreas Persenius.)
 2002-05-18  Matthias Clasen  <maclas@gmx.de>
 
        * tests/markups/fail-36.gmarkup: 
index 311a2c7..9154a4e 100644 (file)
@@ -1,3 +1,17 @@
+Mon May 20 15:35:59 2002  Owen Taylor  <otaylor@redhat.com>
+       * glib/gfileutils.c (get_contents_regfile): Fix double
+       close of file descriptor on error. (#82139, Wayne Schuller)
+       * glib/gspawn.c (close_and_invalidate): Don't close
+       fd's that have already been closed. (Fix from Michael
+       Meeks, #81959)
+       * glib/giochannel.c (g_io_channel_close): If not flushing,
+       dump the contents of the write buffers, so we won't try
+       to write them to an invalid fd later. (Patch from Ron Steinke,
+       fixing #78290, Andreas Persenius.)
 2002-05-18  Matthias Clasen  <maclas@gmx.de>
 
        * tests/markups/fail-36.gmarkup: 
index feeba79..4108e19 100644 (file)
@@ -416,8 +416,6 @@ get_contents_regfile (const gchar *filename,
         {
           if (errno != EINTR) 
             {
-              close (fd);
-
               g_free (buf);
                   
               g_set_error (error,
index f50eee8..c5e8978 100644 (file)
@@ -346,27 +346,35 @@ g_io_channel_shutdown (GIOChannel *channel,
   g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR);
   g_return_val_if_fail (err == NULL || *err == NULL, G_IO_STATUS_ERROR);
 
-  if (flush && channel->write_buf && channel->write_buf->len > 0)
+  if (channel->write_buf && channel->write_buf->len > 0)
     {
-      GIOFlags flags;
+      if (flush)
+        {
+          GIOFlags flags;
       
-      /* Set the channel to blocking, to avoid a busy loop
-       */
-      flags = g_io_channel_get_flags (channel);
-      /* Ignore any errors here, they're irrelevant */
-      g_io_channel_set_flags (channel, flags & ~G_IO_FLAG_NONBLOCK, NULL);
-
-      result = g_io_channel_flush (channel, &tmperr);
+          /* Set the channel to blocking, to avoid a busy loop
+           */
+          flags = g_io_channel_get_flags (channel);
+          /* Ignore any errors here, they're irrelevant */
+          g_io_channel_set_flags (channel, flags & ~G_IO_FLAG_NONBLOCK, NULL);
 
-      if (channel->partial_write_buf[0] != '\0')
-        {
-          g_warning ("Partial character at end of write buffer not flushed.\n");
-          channel->partial_write_buf[0] = '\0';
+          result = g_io_channel_flush (channel, &tmperr);
         }
+      else
+        result = G_IO_STATUS_NORMAL;
+
+      g_string_truncate(channel->write_buf, 0);
     }
   else
     result = G_IO_STATUS_NORMAL;
 
+  if (channel->partial_write_buf[0] != '\0')
+    {
+      if (flush)
+        g_warning ("Partial character at end of write buffer not flushed.\n");
+      channel->partial_write_buf[0] = '\0';
+    }
+
   status = channel->funcs->io_close (channel, err);
 
   channel->close_on_unref = FALSE; /* Because we already did */
index 33960e0..bf152f4 100644 (file)
@@ -119,8 +119,13 @@ close_and_invalidate (gint *fd)
 {
   gint ret;
 
-  ret = close (*fd);
-  *fd = -1;
+  if (*fd < 0)
+    return -1;
+  else
+    {
+      ret = close (*fd);
+      *fd = -1;
+    }
 
   return ret;
 }