1. my enum Signal ( :SIGHUP(1), :SIGINT(2), :SIGQUIT(3), :SIGILL(4), :SIGTRAP(5),
  2. :SIGABRT(6), :SIGEMT(7), :SIGFPE(8), :SIGKILL(9), :SIGBUS(10), :SIGSEGV(11),
  3. :SIGSYS(12), :SIGPIPE(13), :SIGALRM(14), :SIGTERM(15), :SIGURG(16),
  4. :SIGSTOP(17), :SIGTSTP(18), :SIGCONT(19), :SIGCHLD(20), :SIGTTIN(21),
  5. :SIGTTOU(22), :SIGIO(23), :SIGXCPU(24), :SIGXFSZ(25), :SIGVTALRM(26),
  6. :SIGPROF(27), :SIGWINCH(28), :SIGINFO(29), :SIGUSR1(30), :SIGUSR2(31),
  7. :SIGTHR(32), :SIGSTKFLT(116), :SIGPWR(130), :SIGBREAK(221) );
  8. sub signal(Signal $signal, *@signals, :$scheduler = $*SCHEDULER) {
  9. if @signals.grep( { !nqp::istype($_,Signal) } ).list -> @invalid {
  10. die "Found invalid signals: {@invalid}";
  11. }
  12. @signals.unshift: $signal;
  13. @signals .= unique;
  14. state %sigmap =
  15. SIGHUP, nqp::const::SIG_HUP,
  16. SIGINT, nqp::const::SIG_INT,
  17. SIGQUIT, nqp::const::SIG_QUIT,
  18. SIGILL, nqp::const::SIG_ILL,
  19. SIGTRAP, nqp::const::SIG_TRAP,
  20. SIGABRT, nqp::const::SIG_ABRT,
  21. SIGEMT, nqp::const::SIG_EMT,
  22. SIGFPE, nqp::const::SIG_FPE,
  23. SIGKILL, nqp::const::SIG_KILL,
  24. SIGBUS, nqp::const::SIG_BUS,
  25. SIGSEGV, nqp::const::SIG_SEGV,
  26. SIGSYS, nqp::const::SIG_SYS,
  27. SIGPIPE, nqp::const::SIG_PIPE,
  28. SIGALRM, nqp::const::SIG_ALRM,
  29. SIGTERM, nqp::const::SIG_TERM,
  30. SIGURG, nqp::const::SIG_URG,
  31. SIGSTOP, nqp::const::SIG_STOP, # hammer time
  32. SIGTSTP, nqp::const::SIG_TSTP,
  33. SIGCONT, nqp::const::SIG_CONT,
  34. SIGCHLD, nqp::const::SIG_CHLD,
  35. SIGTTIN, nqp::const::SIG_TTIN,
  36. SIGTTOU, nqp::const::SIG_TTOU,
  37. SIGIO, nqp::const::SIG_IO,
  38. SIGXCPU, nqp::const::SIG_XCPU,
  39. SIGXFSZ, nqp::const::SIG_XFSZ,
  40. SIGVTALRM,nqp::const::SIG_VTALRM,
  41. SIGPROF, nqp::const::SIG_PROF,
  42. SIGWINCH, nqp::const::SIG_WINCH,
  43. SIGINFO, nqp::const::SIG_INFO,
  44. SIGUSR1, nqp::const::SIG_USR1,
  45. SIGUSR2, nqp::const::SIG_USR2,
  46. SIGTHR, nqp::const::SIG_THR,
  47. SIGSTKFLT,nqp::const::SIG_STKFLT,
  48. SIGPWR, nqp::const::SIG_PWR,
  49. SIGBREAK, nqp::const::SIG_BREAK
  50. ;
  51. state @known_signals := $*KERNEL.signals;
  52. my class SignalCancellation is repr('AsyncTask') { }
  53. Supply.merge( @signals.map(-> $sig {
  54. my $s = Supplier.new;
  55. nqp::signal($scheduler.queue,
  56. -> $signum { $s.emit(@known_signals[$signum] // $signum) },
  57. nqp::unbox_i(%sigmap{$sig}),
  58. SignalCancellation);
  59. $s.Supply
  60. }) );
  61. }