aboutsummaryrefslogtreecommitdiffstats
path: root/process.c
diff options
context:
space:
mode:
authorngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-19 17:49:27 +0000
committerngoto <ngoto@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-06-19 17:49:27 +0000
commitf59356a85a3c672357e2893ab1ac905bb7655829 (patch)
tree3cf9534aa853c6d8a8c6b3f4233a356311ff76e8 /process.c
parent21bc6f902315dab9567cfe42543328db19e50ce2 (diff)
downloadruby-f59356a85a3c672357e2893ab1ac905bb7655829.tar.gz
* process.c (rb_execarg_parent_start1): new macro ALWAYS_NEED_ENVP
to generate envp_str anytime on Solaris 10 (or earlier version of Solaris) to avoid calling execv() which is async-signal unsafe on Solaris 10. [Bug #11265] [ruby-dev:49089] * process.c (exec_with_sh, proc_exec_cmd): On Solaris 10, because ALWAYS_NEED_ENVP is 1 and envp_str is always generated, execv() in exec_with_sh() and proc_exec_cmd() are never called. To guarantee this, execv() is replaced by a macro to print out error message on Solaris 10. * process.c (proc_exec_sh): Because proc_exec_sh() may be called by rb_proc_exec() with envp_str = Qfalse, execl() is replaced by a macro that calls execle() with "extern char **environ" traditional global variable on Solaris 10. TODO: This may be unsafe and sholud be changed in the future. Although rb_proc_exec() is not used from inside current version of ruby, it may be called by third-party extensions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/process.c b/process.c
index 47dd4b365a..951693f774 100644
--- a/process.c
+++ b/process.c
@@ -285,6 +285,15 @@ static ID id_hertz;
extern ID ruby_static_id_status;
#define id_status ruby_static_id_status
+/* execv and execl are async-signal-safe since SUSv4 (POSIX.1-2008, XPG7) */
+#if defined(__sun) && !defined(_XPG7) /* Solaris 10, 9, ... */
+#define execv(path, argv) (rb_async_bug_errno("unreachable: async-signal-unsafe execv() is called", 0))
+#define execl(path, arg0, arg1, arg2, term) do { extern char **environ; execle((path), (arg0), (arg1), (arg2), (term), (environ)); } while (0)
+#define ALWAYS_NEED_ENVP 1
+#else
+#define ALWAYS_NEED_ENVP 0
+#endif
+
/*#define DEBUG_REDIRECT*/
#if defined(DEBUG_REDIRECT)
@@ -1201,7 +1210,7 @@ exec_with_sh(const char *prog, char **argv, char **envp)
if (envp)
execve("/bin/sh", argv, envp); /* async-signal-safe */
else
- execv("/bin/sh", argv); /* async-signal-safe */
+ execv("/bin/sh", argv); /* async-signal-safe (since SUSv4) */
}
#else
@@ -1261,7 +1270,7 @@ proc_exec_cmd(const char *prog, VALUE argv_str, VALUE envp_str)
if (envp_str)
execve(prog, argv, envp); /* async-signal-safe */
else
- execv(prog, argv); /* async-signal-safe */
+ execv(prog, argv); /* async-signal-safe (since SUSv4) */
preserving_errno(try_with_sh(prog, argv, envp)); /* try_with_sh() is async-signal-safe. */
# if defined(__EMX__) || defined(OS2)
if (new_argv) {
@@ -1312,7 +1321,7 @@ proc_exec_sh(const char *str, VALUE envp_str)
if (envp_str)
execle("/bin/sh", "sh", "-c", str, (char *)NULL, (char **)RSTRING_PTR(envp_str)); /* async-signal-safe */
else
- execl("/bin/sh", "sh", "-c", str, (char *)NULL); /* async-signal-safe */
+ execl("/bin/sh", "sh", "-c", str, (char *)NULL); /* async-signal-safe (since SUSv4) */
#endif
return -1;
#endif /* _WIN32 */
@@ -2360,7 +2369,7 @@ rb_execarg_parent_start1(VALUE execarg_obj)
unsetenv_others = eargp->unsetenv_others_given && eargp->unsetenv_others_do;
envopts = eargp->env_modification;
- if (unsetenv_others || envopts != Qfalse) {
+ if (ALWAYS_NEED_ENVP || unsetenv_others || envopts != Qfalse) {
VALUE envtbl, envp_str, envp_buf;
char *p, *ep;
if (unsetenv_others) {