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

ruby-changes:23892

From: akr <ko1@a...>
Date: Wed, 6 Jun 2012 20:09:37 +0900 (JST)
Subject: [ruby-changes:23892] akr:r35943 (trunk): * process.c (try_with_sh): take envp argument.

akr	2012-06-06 20:09:26 +0900 (Wed, 06 Jun 2012)

  New Revision: 35943

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

  Log:
    * process.c (try_with_sh): take envp argument.
      (exec_with_sh): ditto.  use it for execve.
      (proc_exec_v): provide envp for try_with_sh.

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35942)
+++ ChangeLog	(revision 35943)
@@ -1,3 +1,9 @@
+Wed Jun  6 20:08:01 2012  Tanaka Akira  <akr@f...>
+
+	* process.c (try_with_sh): take envp argument.
+	  (exec_with_sh): ditto.  use it for execve.
+	  (proc_exec_v): provide envp for try_with_sh.
+
 Wed Jun  6 13:25:04 2012  NAKAMURA Usaku  <usa@r...>
 
 	* win32/win32.c, include/ruby/win32.h (rb_w32_wrap_io_handle): new API.
Index: process.c
===================================================================
--- process.c	(revision 35942)
+++ process.c	(revision 35943)
@@ -1046,13 +1046,16 @@
 #if defined(HAVE_FORK) && !defined(__native_client__)
 
 /* try_with_sh and exec_with_sh should be async-signal-safe. */
-#define try_with_sh(prog, argv) ((saved_errno == ENOEXEC) ? exec_with_sh((prog), (argv)) : (void)0)
+#define try_with_sh(prog, argv, envp) ((saved_errno == ENOEXEC) ? exec_with_sh((prog), (argv), (envp)) : (void)0)
 static void
-exec_with_sh(const char *prog, char **argv)
+exec_with_sh(const char *prog, char **argv, char **envp)
 {
     *argv = (char *)prog;
     *--argv = (char *)"sh";
-    execv("/bin/sh", argv); /* async-signal-safe */
+    if (envp)
+        execve("/bin/sh", argv, envp); /* async-signal-safe */
+    else
+        execv("/bin/sh", argv); /* async-signal-safe */
 }
 
 #define ARGV_COUNT(n) ((n)+1)
@@ -1075,6 +1078,7 @@
 #else
     char **argv;
     char fbuf[MAXPATHLEN];
+    char **envp;
 # if defined(__EMX__) || defined(OS2)
     char **new_argv = NULL;
 # endif
@@ -1118,11 +1122,12 @@
     }
 # endif /* __EMX__ */
     before_exec(); /* async-signal-safe if forked_child is true */
+    envp = envp_str ? (char **)RSTRING_PTR(envp_str) : NULL;
     if (envp_str)
-        execve(prog, argv, (char **)RSTRING_PTR(envp_str)); /* async-signal-safe */
+        execve(prog, argv, envp); /* async-signal-safe */
     else
         execv(prog, argv); /* async-signal-safe */
-    preserving_errno(try_with_sh(prog, argv); /* try_with_sh() is async-signal-safe. */
+    preserving_errno(try_with_sh(prog, argv, envp); /* try_with_sh() is async-signal-safe. */
                      after_exec()); /* after_exec() is not async-signal-safe */
 # if defined(__EMX__) || defined(OS2)
     if (new_argv) {
Index: test/ruby/test_process.rb
===================================================================
--- test/ruby/test_process.rb	(revision 35942)
+++ test/ruby/test_process.rb	(revision 35943)
@@ -1297,6 +1297,11 @@
       open("tmp_script.#{$$}", "w") {|f| f.puts "echo $#: $@"; f.chmod(0755)}
       result = IO.popen(["./tmp_script.#{$$}", "a b", "c"]) {|f| f.read}
       assert_equal("2: a b c\n", result, feature)
+
+      open("tmp_script.#{$$}", "w") {|f| f.puts "echo $hghg"; f.chmod(0755)}
+      result = IO.popen([{"hghg" => "mogomogo"}, "./tmp_script.#{$$}", "a b", "c"]) {|f| f.read}
+      assert_equal("mogomogo\n", result, feature)
+
     end
   end if File.executable?("/bin/sh")
 

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

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