public IRubyObject ignore(IRubyObject recv, IRubyObject sig) {
return trap(recv.getRuntime(),sig.toString(),SignalHandler.SIG_IGN);
}
private IRubyObject trap(final Ruby runtime, final String signalName, final SignalHandler handler) {
final SignalHandler oldHandler;
final Signal signal;
try {
signal = new Signal(signalName);
} catch (Throwable e) {
return runtime.getNil();
}
try {
oldHandler = Signal.handle(signal, handler);
} catch (Exception e) {
throw runtime.newArgumentError(e.getMessage());
}
synchronized (original) {
if (!original.containsKey(signal))
original.put(signal,oldHandler);
}
BlockCallback callback = null;
if (oldHandler instanceof JRubySignalHandler) {
JRubySignalHandler jsHandler = (JRubySignalHandler) oldHandler;
if (jsHandler.blockCallback != null) {
callback = jsHandler.blockCallback;
} else {
return jsHandler.block;
}
}
if (callback == null) {
callback = new BlockCallback() {
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
oldHandler.handle(signal);
return runtime.getNil();
}
};
}
final RubyModule signalModule = runtime.getModule("Signal");