From: Chirag Mistry Date: 2008-01-21T15:49:11+09:00 Subject: Re: Input related to signal usage in Ruby 1.9 implementation ------=_Part_7873_978146.1200898156765 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi All We had given some inputs for the signal usage in Ruby 1.9 based on our study of the earlier version of Ruby 1.9 code. We have again analyzed the latest code of Ruby 1.9 for the defects that we found during our initial investigation of earlier version of Ruby 1.9 code. We have observed some changes in the latest code and have accordingly modified the defect description to reflect the latest code and new line numbers. Given below are the updated defect descriptions for the signal usage in Ruby 1.9 implementation. It would be better to fix these defects if our understanding is correct. Please give your feedback on the same. 1. In file trunk/thread_pthread.c, at line no: 153 In the "Init_native_thread" function, posix_signal function is called with SIGVTALRM value setting an empty function as signal handler. The "Init_native_thread" function is indirectly called from ruby_init(). As per our understanding, SIGVTALRM is no longer a reserved signal in Ruby 1.9 implementation and therefore no signal handler should be installed for it. 2. 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 12/20/07, Chirag Mistry wrote: > > > We have study the code of yarv (Ruby 1.9 implementation) and as per our > understanding there are few defects related to signal usage in Ruby 1.9 > implementation. Please give feedback on it. > > 1. In file trunk/signal.c, at line number 788: > SIGVTALRM seems a reserved signal in the ruby interpreter as per > implementation of trap function of Signal module. But, we did not find > any reference related with usage of this signal. In earlier versions of > ruby, SIGVTALRM was used to implement cooperative multitasking (user > space multithreading) and this signal was reserved for proper > functioning of Thread module. So in Ruby 1.9, SIGVTALRM is not used any > more. Empty signal handler is installed for SIGVTALRM in > Init_native_thread() function. > > 2. In file trunk/eval.c, at line number 144: > In ruby_finalize_1 function, signal handler SIG_DFL is installed for > SIGINT signal. It gets called automatically when ruby interpreter is > unloaded (normally or abnormally). > It may create problem when ruby interpreter is embedded in a process for > a limited period of time. Because ruby_finalize_1 sets signal handler > for SIGINT to SIG_DFL without checking previously installed signal > handler. > > Regards > Chirag > ------=_Part_7873_978146.1200898156765 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Hi All
 
We had given some inputs for the signal usage in Ruby 1.9 based on our study of the earlier version of Ruby 1.9 code. We have again analyzed the latest code of Ruby 1.9 for the defects that we found during our initial investigation of earlier version of Ruby 1.9 code. We have observed some changes in the latest code and have accordingly modified the defect description to reflect the latest code and new line numbers.
Given below are the updated defect descriptions for the signal usage in Ruby 1.9 implementation. It would be better to fix these defects if our understanding is correct. Please give your feedback on the same. 
 
1. In file trunk/thread_pthread.c, at line no: 153 
 
In the "Init_native_thread" function, posix_signal function is called with SIGVTALRM value setting an empty function as signal handler. The "Init_native_thread" function is indirectly called from ruby_init().
As per our understanding, SIGVTALRM is no longer a reserved signal in Ruby 1.9 implementation and therefore no signal handler should be installed for it.  

2. 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 12/20/07, Chirag Mistry <chirag80bece@gmail.com> wrote:
 
We have study the code of yarv (Ruby 1.9 implementation) and as per our
understanding there are few defects related to signal usage in Ruby 1.9
implementation. Please give feedback on it. 

1. In file trunk/signal.c, at line number 788:
SIGVTALRM seems a reserved signal in the ruby interpreter as per
implementation of trap function of Signal module. But, we did not find
any reference related with usage of this signal. In earlier versions of
ruby, SIGVTALRM was used to implement cooperative multitasking (user
space multithreading) and this signal was reserved for proper
functioning of Thread module. So in Ruby 1.9, SIGVTALRM is not used any
more. Empty signal handler is installed for SIGVTALRM in
Init_native_thread() function.

2. In file trunk/eval.c, at line number 144:
In ruby_finalize_1 function, signal handler SIG_DFL is installed for
SIGINT signal. It gets called automatically when ruby interpreter is
unloaded (normally or abnormally).
It may create problem when ruby interpreter is embedded in a process for
a limited period of time. Because ruby_finalize_1 sets signal handler
for SIGINT to SIG_DFL without checking previously installed signal
handler.
 
Regards
Chirag

------=_Part_7873_978146.1200898156765--