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

ruby-changes:4741

From: ko1@a...
Date: Wed, 30 Apr 2008 14:40:43 +0900 (JST)
Subject: [ruby-changes:4741] akr - Ruby:r16235 (trunk): * process.c (check_exec_redirect_fd): prohibit duplex IO.

akr	2008-04-30 14:40:19 +0900 (Wed, 30 Apr 2008)

  New Revision: 16235

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/intern.h
    trunk/io.c
    trunk/process.c
    trunk/test/ruby/test_process.rb

  Log:
    * process.c (check_exec_redirect_fd): prohibit duplex IO.
      (check_exec_fds): record maxhint even if close_others is not
      specified.
      (rb_exec_arg_fixup): renamed from rb_exec_arg_fix.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_process.rb?r1=16235&r2=16234&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16235&r2=16234&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/io.c?r1=16235&r2=16234&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/process.c?r1=16235&r2=16234&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/intern.h?r1=16235&r2=16234&diff_format=u

Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 16234)
+++ include/ruby/intern.h	(revision 16235)
@@ -455,7 +455,7 @@
 int rb_proc_exec(const char*);
 VALUE rb_exec_arg_init(int argc, VALUE *argv, int accept_shell, struct rb_exec_arg *e);
 int rb_exec_arg_addopt(struct rb_exec_arg *e, VALUE key, VALUE val);
-void rb_exec_arg_fix(struct rb_exec_arg *e);
+void rb_exec_arg_fixup(struct rb_exec_arg *e);
 int rb_exec(const struct rb_exec_arg*);
 rb_pid_t rb_fork(int*, int (*)(void*), void*, VALUE);
 VALUE rb_f_exec(int,VALUE*);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 16234)
+++ ChangeLog	(revision 16235)
@@ -1,3 +1,10 @@
+Wed Apr 30 12:32:39 2008  Tanaka Akira  <akr@f...>
+
+	* process.c (check_exec_redirect_fd): prohibit duplex IO.
+	  (check_exec_fds): record maxhint even if close_others is not
+	  specified.
+	  (rb_exec_arg_fixup): renamed from rb_exec_arg_fix.
+
 Mon Apr 28 20:24:27 2008  Tadayoshi Funaba  <tadf@d...>
 
 	* rational.c (nurat_marshal_load): checks the given
Index: io.c
===================================================================
--- io.c	(revision 16234)
+++ io.c	(revision 16235)
@@ -3761,7 +3761,7 @@
         rb_sys_fail(cmd);
     }
     if (eargp) {
-        rb_exec_arg_fix(arg.execp);
+        rb_exec_arg_fixup(arg.execp);
 	pid = rb_fork(&status, popen_exec, &arg, arg.execp->redirect_fds);
     }
     else {
Index: process.c
===================================================================
--- process.c	(revision 16234)
+++ process.c	(revision 16235)
@@ -1250,6 +1250,8 @@
     else if (!NIL_P(tmp = rb_check_convert_type(v, T_FILE, "IO", "to_io"))) {
         rb_io_t *fptr;
         GetOpenFile(tmp, fptr);
+        if (fptr->tied_io_for_writing)
+            rb_raise(rb_eArgError, "duplex IO redirection");
         fd = fptr->fd;
     }
     else {
@@ -1510,7 +1512,7 @@
             }
         }
     }
-    if (RTEST(rb_ary_entry(options, EXEC_OPTION_CLOSE_OTHERS))) {
+    if (rb_ary_entry(options, EXEC_OPTION_CLOSE_OTHERS) != Qfalse) {
         rb_ary_store(options, EXEC_OPTION_CLOSE_OTHERS, INT2FIX(maxhint));
     }
     return h;
@@ -1652,7 +1654,7 @@
 }
 
 void
-rb_exec_arg_fix(struct rb_exec_arg *e)
+rb_exec_arg_fixup(struct rb_exec_arg *e)
 {
     e->redirect_fds = check_exec_fds(e->options);
 }
@@ -1697,7 +1699,7 @@
     rb_exec_arg_init(argc, argv, Qtrue, &earg);
     if (NIL_P(rb_ary_entry(earg.options, EXEC_OPTION_CLOSE_OTHERS)))
         rb_exec_arg_addopt(&earg, ID2SYM(rb_intern("close_others")), Qfalse);
-    rb_exec_arg_fix(&earg);
+    rb_exec_arg_fixup(&earg);
 
     rb_exec(&earg);
     rb_sys_fail(earg.prog);
@@ -2047,7 +2049,7 @@
 #ifdef HAVE_FORK
     obj = rb_ary_entry(options, EXEC_OPTION_CLOSE_OTHERS);
     if (obj != Qfalse) {
-        rb_close_before_exec(3, FIXNUM_P(obj) ? FIX2LONG(obj) : 0, e->redirect_fds);
+        rb_close_before_exec(3, FIX2LONG(obj), e->redirect_fds);
     }
 #endif
 
@@ -2547,7 +2549,7 @@
         VALUE v = default_close_others ? Qtrue : Qfalse;
         rb_exec_arg_addopt(&earg, ID2SYM(rb_intern("close_others")), v);
     }
-    rb_exec_arg_fix(&earg);
+    rb_exec_arg_fixup(&earg);
 
 #if defined HAVE_FORK
     status = rb_fork(&status, rb_exec_atfork, &earg, earg.redirect_fds);
@@ -2746,6 +2748,8 @@
  *  spawn closes all non-standard unspecified descriptors by default.
  *  The "standard" descriptors are 0, 1 and 2.
  *  This behavior is specified by :close_others option.
+ *  :close_others doesn't affect the standard descriptors which are
+ *  closed only if :close is specified explicitly.
  *
  *    pid = spawn(command, :close_others=>true)  # close 3,4,5,... (default)
  *    pid = spawn(command, :close_others=>false) # don't close 3,4,5,...
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 16234)
+++ test/ruby/test_process.rb	(revision 16235)
@@ -523,6 +523,24 @@
     }
   end
 
+  def test_execopts_redirect_self
+    with_pipe {|r, w|
+      w << "haha\n"
+      w.close
+      r.close_on_exec = true
+      IO.popen([RUBY, "-e", "print IO.new(#{r.fileno}).read", r.fileno=>r.fileno, :close_others=>false]) {|io|
+        assert_equal("haha\n", io.read)
+      }
+    }
+  end
+
+  def test_execopts_duplex_io
+    IO.popen("#{RUBY} -e ''", "r+") {|duplex|
+      assert_raise(ArgumentError) { system("#{RUBY} -e ''", duplex=>STDOUT) }
+      assert_raise(ArgumentError) { system("#{RUBY} -e ''", STDOUT=>duplex) }
+    }
+  end
+
   def test_execopts_modification
     h = {}
     Process.wait spawn(*TRUECOMMAND, h)

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

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