Feature #5613 » signame.patch
signal.c | ||
---|---|---|
return 0;
|
||
}
|
||
/*
|
||
* call-seq:
|
||
* Signal.signame(signo) -> string
|
||
*
|
||
* convert signal number to signal name
|
||
*
|
||
* Signal.trap("INT") { |signo| puts Signal.signame(signo) }
|
||
* Process.kill("INT", 0)
|
||
*
|
||
* <em>produces:</em>
|
||
*
|
||
* INT
|
||
*/
|
||
static VALUE
|
||
sig_signame(VALUE recv, VALUE signo)
|
||
{
|
||
char* signame;
|
||
signame = signo2signm(NUM2INT(signo));
|
||
return rb_str_new_cstr(signame);
|
||
}
|
||
const char *
|
||
ruby_signal_name(int no)
|
||
{
|
||
... | ... | |
rb_define_global_function("trap", sig_trap, -1);
|
||
rb_define_module_function(mSignal, "trap", sig_trap, -1);
|
||
rb_define_module_function(mSignal, "list", sig_list, 0);
|
||
rb_define_module_function(mSignal, "signame", sig_signame, 1);
|
||
rb_define_method(rb_eSignal, "initialize", esignal_init, -1);
|
||
rb_define_method(rb_eSignal, "signo", esignal_signo, 0);
|
test/ruby/test_signal.rb | ||
---|---|---|
}
|
||
end
|
||
def test_signame
|
||
10.times do
|
||
caught = 0
|
||
signame = "hoge"
|
||
Signal.trap("INT") { |signo| signame = Signal.signame(signo); caught = 1; }
|
||
Process.kill("INT", 0)
|
||
sleep 0.01 while caught==0
|
||
assert_equal(signame, "INT")
|
||
end
|
||
end
|
||
end
|