[前][次][番号順一覧][スレッド一覧]

ruby-changes:9499

From: yugui <ko1@a...>
Date: Thu, 25 Dec 2008 18:59:28 +0900 (JST)
Subject: [ruby-changes:9499] Ruby:r21038 (ruby_1_9_1): merges r20987 from trunk into ruby_1_9_1.

yugui	2008-12-25 18:57:40 +0900 (Thu, 25 Dec 2008)

  New Revision: 21038

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21038

  Log:
    merges r20987 from trunk into ruby_1_9_1.
    * io.c (fptr_finalize): close the IO object even if close(2) is failed.

  Modified files:
    branches/ruby_1_9_1/ChangeLog
    branches/ruby_1_9_1/io.c

Index: ruby_1_9_1/ChangeLog
===================================================================
--- ruby_1_9_1/ChangeLog	(revision 21037)
+++ ruby_1_9_1/ChangeLog	(revision 21038)
@@ -1,3 +1,7 @@
+Thu Dec 25 15:07:22 2008  Tanaka Akira  <akr@f...>
+
+	* io.c (fptr_finalize): close the IO object even if close(2) is failed.
+
 Thu Dec 25 14:51:43 2008  NAKAMURA Usaku  <usa@r...>
 
 	* lib/rdoc/parser.rb (RDoc::Parser.binary?): should read in binary mode.
Index: ruby_1_9_1/io.c
===================================================================
--- ruby_1_9_1/io.c	(revision 21037)
+++ ruby_1_9_1/io.c	(revision 21038)
@@ -3090,7 +3090,7 @@
 static void
 fptr_finalize(rb_io_t *fptr, int noraise)
 {
-    int ebadf = 0;
+    int close_failure = 0;
     if (fptr->writeconv) {
 	if (fptr->write_lock) {
 	    struct finish_writeconv_arg arg;
@@ -3110,29 +3110,22 @@
 	return;
     }
     if (fptr->stdio_file) {
-        if (fclose(fptr->stdio_file) < 0 && !noraise) {
-            /* fptr->stdio_file is deallocated anyway */
-            fptr->stdio_file = 0;
-            fptr->fd = -1;
-            rb_sys_fail_path(fptr->pathv);
-        }
+        /* fptr->stdio_file is deallocated anyway
+         * even if fclose failed.  */
+        if (fclose(fptr->stdio_file) < 0)
+            close_failure = 1;
     }
     else if (0 <= fptr->fd) {
-        if (close(fptr->fd) < 0 && !noraise) {
-            if (errno != EBADF) {
-                /* fptr->fd is still not closed */
-                rb_sys_fail_path(fptr->pathv);
-            }
-            else {
-                /* fptr->fd is already closed. */
-                ebadf = 1;
-            }
-        }
+        /* fptr->fd may be closed even if close fails.
+         * POSIX doesn't specify it.
+         * We assumes it is closed.  */
+        if (close(fptr->fd) < 0)
+            close_failure = 1;
     }
     fptr->fd = -1;
     fptr->stdio_file = 0;
     fptr->mode &= ~(FMODE_READABLE|FMODE_WRITABLE);
-    if (ebadf) {
+    if (close_failure && !noraise) {
         rb_sys_fail_path(fptr->pathv);
     }
 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]