Project

General

Profile

Feature #5613 » signame.patch

kosaki (Motohiro KOSAKI), 11/09/2012 01:19 AM

View differences:

signal.c
207 207
    return 0;
208 208
}
209 209

  
210
/*
211
 * call-seq:
212
 *    Signal.signame(signo)              ->  string
213
 *
214
 *  convert signal number to signal name
215
 *
216
 * Signal.trap("INT") { |signo| puts Signal.signame(signo) }
217
 * Process.kill("INT", 0)
218
 *
219
 *  <em>produces:</em>
220
 *
221
 *     INT
222
 */
223
static VALUE
224
sig_signame(VALUE recv, VALUE signo)
225
{
226
    char* signame;
227

  
228
    signame = signo2signm(NUM2INT(signo));
229
    return rb_str_new_cstr(signame);
230
}
231

  
210 232
const char *
211 233
ruby_signal_name(int no)
212 234
{
......
1086 1108
    rb_define_global_function("trap", sig_trap, -1);
1087 1109
    rb_define_module_function(mSignal, "trap", sig_trap, -1);
1088 1110
    rb_define_module_function(mSignal, "list", sig_list, 0);
1111
    rb_define_module_function(mSignal, "signame", sig_signame, 1);
1089 1112

  
1090 1113
    rb_define_method(rb_eSignal, "initialize", esignal_init, -1);
1091 1114
    rb_define_method(rb_eSignal, "signo", esignal_signo, 0);
test/ruby/test_signal.rb
240 240
    }
241 241
  end
242 242

  
243
  def test_signame
244
    10.times do
245
      caught = 0
246
      signame = "hoge"
247

  
248
      Signal.trap("INT") { |signo| signame = Signal.signame(signo); caught = 1;  }
249
      Process.kill("INT", 0)
250

  
251
      sleep 0.01 while caught==0
252
      assert_equal(signame, "INT")
253
    end
254
  end
243 255
end