> * R does use SA_ONSTACK for SIGSEGV, SIGILL, and SIGBUS signals, but
> curiously not for SIGINT. Drat! :-)
For a signal like SIGINT, it's not obvious to me when you would chain
back and when you would not.
Are you suggesting that the Go runtime
should pass SIGINT to any os/signal.Notify channel, and then always
invoke the existing signal handler if there is one?
ctrlC_Chan := make(chan os.Signal, 1); signal.Notify(ctrlC_Chan, os.Interrupt)
...
>
> And it would be fragile to depend on such an implementation detail.
> But if I was desperately pressed into a corner, reflection could be used to
> read it, no?
No, the reflect package doesn't let you get around what the language
permits. You would have to modify the runtime package.
> b) If I could run some C code before the Go runtime is initialized
> upon library load, I could save the previous handler in a global
> myself. Perhaps I just need to make a thin wrapper library that
> loads the c-shared library as a dependency. That would keep
> things more portable.
Yes, that should work.
struct sigaction starting_act;
void __attribute__ ((constructor)) my_init(void) { sigaction(SIGINT, NULL, &starting_act);}
The only downside here is thtat this is likely gcc or gcc-and-clang only, this ((constructor)) gnu attribute.
So excellent progress! I'm still stuck on OSX because there seems to be some kind of segfaulting bug in the c-shared signal handling on OSX ( I filed https://github.com/golang/go/issues/13034 for this), but I'm almost there(!) If you have thoughts on how I might work around 13034, I would be most happy to try them out.
Jason