summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-28 15:24:18 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-28 15:24:18 +0000
commitbde7a62f9150d8a147c4e9b721ced4c2beb9600a (patch)
treef394543320f73aa2460f6478c4fabcefee6ded46 /process.c
parented02c4122a67f209c7c9c4ebdd09647d0ae88e6d (diff)
* process.c (before_exec, after_exec): change from macro to function.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/process.c b/process.c
index af55a0e412..e89d82413a 100644
--- a/process.c
+++ b/process.c
@@ -992,33 +992,47 @@ static RETSIGTYPE (*saved_sigpipe_handler)(int) = 0;
# define signal(a,b) posix_signal((a),(b))
#endif
-static void save_sigpipe(void)
+static void before_exec(void)
{
+ /*
+ * signalmask is inherited across exec() and almost system commands don't
+ * work if signalmask is blocked.
+ */
+ rb_enable_interrupt();
+
#ifdef SIGPIPE
/*
- * Some OS commands don't initialize signal handler properly. Thus we have to
- * reset signal handler before exec(). Otherwise, system() and similar child process
- * interaction might fail. (e.g. ruby -e "system 'yes | ls'") [ruby-dev:12261]
+ * Some OS commands don't initialize signal handler properly. Thus we have
+ * to reset signal handler before exec(). Otherwise, system() and similar
+ * child process interaction might fail. (e.g. ruby -e "system 'yes | ls'")
+ * [ruby-dev:12261]
*/
saved_sigpipe_handler = signal(SIGPIPE, SIG_DFL);
#endif
+
+ if (!forked_child) {
+ /*
+ * On old MacOS X, exec() may return ENOTSUPP if the process have
+ * multiple threads. Therefore we have to kill internal threads at once.
+ * [ruby-core: 10583]
+ */
+ rb_thread_stop_timer_thread();
+ }
}
-static void restore_sigpipe(void)
+static void after_exec(void)
{
+ rb_thread_reset_timer_thread();
+ rb_thread_start_timer_thread();
+
#ifdef SIGPIPE
signal(SIGPIPE, saved_sigpipe_handler);
#endif
+
+ forked_child = 0;
+ rb_disable_interrupt();
}
-/*
- * On old MacOS X, exec() may return ENOTSUPP if the process have multiple threads.
- * Therefore we have to kill internal threads at once. [ruby-core: 10583]
- */
-#define before_exec() \
- (rb_enable_interrupt(), save_sigpipe(), (void)(forked_child ? 0 : (rb_thread_stop_timer_thread(), 1)))
-#define after_exec() \
- (rb_thread_reset_timer_thread(), rb_thread_start_timer_thread(), forked_child = 0, restore_sigpipe(), rb_disable_interrupt())
#define before_fork() before_exec()
#define after_fork() (GET_THREAD()->thrown_errinfo = 0, after_exec())