From jeff.a.ryan at gmail.com  Tue May 22 22:31:07 2012
From: jeff.a.ryan at gmail.com (Jeffrey Ryan)
Date: Tue, 22 May 2012 15:31:07 -0500
Subject: [Rd] Capturing signals from within external libs
Message-ID: <CBE161BB.3E916%jeff.a.ryan@gmail.com>

I have a continuous loop running in an external library that I am calling
from C (R API).  This loop is processing events in real time with the
possibility of significant lag between events.

When processing an event, I can make use of R_CheckUserInterrupt, but
while the external library code is waiting on a new event, I don't have an
opportunity to call this - my entry points are only on events.

I can capture a SIGINT by redefining signal(SIGINT, myhandler) before
calling the lib, but I am somewhat at a loss in terms of what I can do
within the handler that would let me pass control back to R.

void myhandler (int s) {
  error("interrupt caught!");
}

Works, but I am sure it isn't supposed to.  In fact I know it is wrong,
since after interrupting once SIGINTs are subsequently ignored, even if I
reset the signal to the original one (as returned by the first call to
signal).

Currently I can exit(1) of course, but that is tragically bad form IMO,
though will work in my situation.

In short, what is the proper way to handle SIGINT in external code that is
called from R, that allows R to handle the signal.  Thoughts or
suggestions appreciated.

Thanks,
Jeff



[Rd] Capturing signals from within external libs
Jeffrey Ryan