Set the receiver as the handler of the signal

If safely, receiver will be called when check_signals in invoked otherwise the receiver is invoked when the signal is raised, it may crash the Nit system but is unavoidable for unstoppable signals.

Property definitions

signals $ SignalHandler :: handle_signal
	# Set the receiver as the handler of the signal
	#
	# If `safely`, receiver will be called when `check_signals` in invoked
	# otherwise the receiver is invoked when the signal is raised, it may
	# crash the Nit system but is unavoidable for unstoppable signals.
	fun handle_signal(signal: Int, safely: Bool) import receive_signal `{
		if (signal < 32 && signal >=0) {
			struct sigaction act;
			sigemptyset(&act.sa_mask);
			act.sa_flags = 0;
			act.sa_handler = receiver;

			sigaction(signal, &act, NULL);

		#ifdef SignalHandler_decr_ref
			SignalHandler last_handler = (SignalHandler)nit_signals_list[signal].handler;
			if (last_handler != NULL)
				SignalHandler_decr_ref(last_handler);
		#endif

			nit_signals_list[signal].handler = self;

		#ifdef SignalHandler_incr_ref
			SignalHandler_incr_ref(self);
		#endif

			nit_signals_list[signal].safely = safely;

			nit_SignalHandler_receive_signal =
				(void (*)(void*, long))&SignalHandler_receive_signal;
		}
	`}
lib/signals/signals.nit:139,2--170,3