[macruby-changes] [2459] MacRuby/trunk/io.c

source_changes at macosforge.org source_changes at macosforge.org
Thu Sep 3 13:20:15 PDT 2009


Revision: 2459
          http://trac.macosforge.org/projects/ruby/changeset/2459
Author:   lsansonetti at apple.com
Date:     2009-09-03 13:20:11 -0700 (Thu, 03 Sep 2009)
Log Message:
-----------
before yielding the pipe, make sure we close the write pair in case we do a read-only one

Modified Paths:
--------------
    MacRuby/trunk/io.c

Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c	2009-09-03 07:51:13 UTC (rev 2458)
+++ MacRuby/trunk/io.c	2009-09-03 20:20:11 UTC (rev 2459)
@@ -2000,16 +2000,6 @@
 	rb_sys_fail("pipe() failed");
     }
 
-    // Confusingly enough, FMODE_WRITABLE means 'write-only'
-    // and FMODE_READABLE means 'read-only'.
-    const int fmode = convert_mode_string_to_fmode(mode);
-    if (fmode != FMODE_WRITABLE) {
-	io_struct->read_fd = fd[0];
-    }
-    if (fmode != FMODE_READABLE) {
-	io_struct->write_fd = fd[1];
-    }
-
     rb_sys_fail_unless(posix_spawn_file_actions_init(&actions),
 	    "could not init file actions");
     rb_sys_fail_unless(posix_spawn_file_actions_adddup2(&actions, fd[1],
@@ -2036,6 +2026,19 @@
     io_struct->pid = pid;
     io_struct->sync = mode & FMODE_SYNC;
 
+    // Confusingly enough, FMODE_WRITABLE means 'write-only'
+    // and FMODE_READABLE means 'read-only'.
+    const int fmode = convert_mode_string_to_fmode(mode);
+    if (fmode != FMODE_WRITABLE) {
+	io_struct->read_fd = fd[0];
+    }
+    if (fmode != FMODE_READABLE) {
+	io_struct->write_fd = fd[1];
+    }
+    else {
+	close(fd[1]);	
+    }
+
     return io;
 }
 
@@ -3242,12 +3245,6 @@
     if (waitpid(io_s->pid, &status, 0) != -1) {
 	rb_last_status_set(status, io_s->pid);
 	io_s->pid = -1;
-#if 0
-	if (!WIFEXITED(status) || WEXITSTATUS(status) > 0) {
-	    rb_io_close(io, 0);
-	    return rb_str_new2("");
-	}
-#endif
     }
 
     VALUE bstr = rb_bytestring_new();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090903/56b61ae5/attachment.html>


More information about the macruby-changes mailing list