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

ruby-changes:22843

From: akr <ko1@a...>
Date: Sat, 3 Mar 2012 22:54:05 +0900 (JST)
Subject: [ruby-changes:22843] akr:r34892 (trunk): * process.c (rb_run_exec_options_err): chdir at last to interpret

akr	2012-03-03 22:53:53 +0900 (Sat, 03 Mar 2012)

  New Revision: 34892

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

  Log:
    * process.c (rb_run_exec_options_err): chdir at last to interpret
      relative pathnames from the current directory of the parent process.

  Modified files:
    trunk/ChangeLog
    trunk/process.c
    trunk/test/ruby/test_process.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34891)
+++ ChangeLog	(revision 34892)
@@ -1,3 +1,8 @@
+Sat Mar  3 22:51:46 2012  Tanaka Akira  <akr@f...>
+
+	* process.c (rb_run_exec_options_err): chdir at last to interpret
+	  relative pathnames from the current directory of the parent process.
+
 Sat Mar  3 12:20:44 2012  Tadayoshi Funaba  <tadf@d...>
 
 	* ext/date/date_strftime.c: reassigned some variables.
Index: process.c
===================================================================
--- process.c	(revision 34891)
+++ process.c	(revision 34892)
@@ -2367,20 +2367,6 @@
         }
     }
 
-    obj = rb_ary_entry(options, EXEC_OPTION_CHDIR);
-    if (!NIL_P(obj)) {
-        if (!NIL_P(soptions)) {
-            char *cwd = my_getcwd();
-            rb_ary_store(soptions, EXEC_OPTION_CHDIR,
-                         hide_obj(rb_str_new2(cwd)));
-            xfree(cwd);
-        }
-        if (chdir(RSTRING_PTR(obj)) == -1) {
-            ERRMSG("chdir");
-            return -1;
-        }
-    }
-
     obj = rb_ary_entry(options, EXEC_OPTION_UMASK);
     if (!NIL_P(obj)) {
         mode_t mask = NUM2MODET(obj);
@@ -2424,6 +2410,20 @@
             return -1;
     }
 
+    obj = rb_ary_entry(options, EXEC_OPTION_CHDIR);
+    if (!NIL_P(obj)) {
+        if (!NIL_P(soptions)) {
+            char *cwd = my_getcwd();
+            rb_ary_store(soptions, EXEC_OPTION_CHDIR,
+                         hide_obj(rb_str_new2(cwd)));
+            xfree(cwd);
+        }
+        if (chdir(RSTRING_PTR(obj)) == -1) {
+            ERRMSG("chdir");
+            return -1;
+        }
+    }
+
     return 0;
 }
 
@@ -3141,8 +3141,6 @@
  *      resource limit: resourcename is core, cpu, data, etc.  See Process.setrlimit.
  *        :rlimit_resourcename => limit
  *        :rlimit_resourcename => [cur_limit, max_limit]
- *      current directory:
- *        :chdir => str
  *      umask:
  *        :umask => int
  *      redirection:
@@ -3165,6 +3163,8 @@
  *          io      : the file descriptor specified as io.fileno
  *      file descriptor inheritance: close non-redirected non-standard fds (3, 4, 5, ...) or not
  *        :close_others => true  : don't inherit
+ *      current directory:
+ *        :chdir => str
  *
  *  If a hash is given as +env+, the environment is
  *  updated by +env+ before <code>exec(2)</code> in the child process.
@@ -3208,10 +3208,6 @@
  *    pid = spawn(command, :rlimit_core=>max) # enable core dump
  *    pid = spawn(command, :rlimit_core=>0) # never dump core.
  *
- *  The <code>:chdir</code> key in +options+ specifies the current directory.
- *
- *    pid = spawn(command, :chdir=>"/var/tmp")
- *
  *  The <code>:umask</code> key in +options+ specifies the umask.
  *
  *    pid = spawn(command, :umask=>077)
@@ -3291,6 +3287,10 @@
  *    io = IO.popen(["sh", "-c", "echo out; echo err >&2", :err=>[:child, :out]])
  *    p io.read #=> "out\nerr\n"
  *
+ *  The <code>:chdir</code> key in +options+ specifies the current directory.
+ *
+ *    pid = spawn(command, :chdir=>"/var/tmp")
+ *
  *  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.
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 34891)
+++ test/ruby/test_process.rb	(revision 34892)
@@ -327,6 +327,16 @@
     }
   end
 
+  def test_execopts_open_chdir
+    with_tmpchdir {|d|
+      Dir.mkdir "foo"
+      system(*PWD, :chdir => "foo", :out => "open_chdir_test")
+      assert(File.exist?("open_chdir_test"))
+      assert(!File.exist?("foo/open_chdir_test"))
+      assert_equal("#{d}/foo", File.read("open_chdir_test").chomp)
+    }
+  end
+
   UMASK = [RUBY, '-e', 'printf "%04o\n", File.umask']
 
   def test_execopts_umask

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

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