Hi All
I was going through the code of Ruby 1.9. I got some defects related to
the
usage of some signal.
Given below are the defect descriptions for the signal usage of SIGINT
in
Ruby 1.9 implementation.
Defect Description: Handling SIGINT
"ruby_finalize_1"(In file trunk/eval.c, at line no: 142) function calls
"ruby_sig_finalize function" (In file trunk/signal.c, at line no: 996).
In
"ruby_sig_finalize", signal handler SIG_IGN is installed for SIGINT
signal
and then signal handler SIG_DFL is installed for SIGINT signal if the
previously installed signal handler was the Ruby handler ("sighandler").
As
per our understanding, it may create problem when ruby interpreter is
embedded in a process for a limited period of time. It should not
install
signal handler SIG_IGN for SIGINT signal.
Existing code of ruby_sig_finalize is following:
---------------------------------------------------------------------
void ruby_sig_finalize()
{
sighandler_t oldfunc;
oldfunc = ruby_signal(SIGINT, SIG_IGN);
if (oldfunc == sighandler) {
ruby_signal(SIGINT, SIG_DFL);
}
}
We can do below correction in ruby_sig_finalize function:
----------------------------------------------------------------------
void ruby_sig_finalize()
{
sighandler_t oldfunc;
oldfunc = ruby_signal(SIGINT, SIG_DFL);
if (oldfunc != sighandler) {
ruby_signal(SIGINT, oldfunc);
}
}
Regards
Chirag
on 06.03.2008 10:53
on 07.03.2008 04:15
Hi, At Thu, 6 Mar 2008 18:52:14 +0900, Chirag Mistry wrote in [ruby-core:15809]: > per our understanding, it may create problem when ruby interpreter is > embedded in a process for a limited period of time. It should not install > signal handler SIG_IGN for SIGINT signal. It would be true, when embedded, but might not be true otherwise. Index: signal.c =================================================================== --- signal.c (revision 15720) +++ signal.c (working copy) @@ -1004,8 +1004,25 @@ ruby_sig_finalize() sighandler_t oldfunc; - oldfunc = ruby_signal(SIGINT, SIG_IGN); +#ifdef POSIX_SIGNAL + struct sigaction oldact; + MEMZERO(&oldact, struct sigaction, 1); + sigaction(SIGINT, NULL, &oldact); +#ifdef SA_SIGINFO + if (oldact.sa_flags & SA_SIGINFO) + oldfunc = (sighandler_t)oldact.sa_sigaction; + else +#else + oldfunc = oldact.sa_handler; +#endif if (oldfunc == sighandler) { ruby_signal(SIGINT, SIG_DFL); } +#else + oldfunc = ruby_signal(SIGINT, SIG_IGN); + if (oldfunc == sighandler) { + oldfunc = SIG_DFL; + } + ruby_signal(SIGINT, oldfunc); +#endif }