Logo Search packages:      
Sourcecode: kaya version File versions  Download package

signald.cc

#include <signal.h>
#include <unistd.h>

#include "signald.h"

#include "VM.h"

Value** hlist = (Value**)GC_MALLOC_UNCOLLECTABLE(sizeof(Value*)*63);

void callHandler(int signo)
{
    signal(signo,callHandler);
    // Block all other signals while we're working.
    sigset_t blk;                 
    sigset_t sigsv;               

    sigfillset(&blk);             
    sigdelset(&blk,signo);       
    sigprocmask(SIG_BLOCK,&blk,&sigsv); /* Block sigs */

    Value* h = hlist[signo];
// FIXME: Doesn't work yet
/*    cout << "Calling handler for signal " << signo << endl;
    cout << "Got handler " << h << endl;
    cout << "Got handler " << h->getRaw() << endl;
    cout << stacksize << endl;
    PUSH(MKINT(signo));
    cout << stacksize << endl;
    CALL(GETFUN(h));
    cout << stacksize << endl;
*/
    sigprocmask(SIG_SETMASK,&sigsv,0);
}

void setHandler(int signo, Value* handlerfn)
{
    struct sigaction sa_old;
    struct sigaction sa_new;

    sa_new.sa_handler = callHandler;    // Point to our function
    hlist[signo] = handlerfn; // Set it in our lookup table
    cout << "Set handler to " << handlerfn << endl;
    cout << "Set handler value to " << handlerfn->getRaw() << endl;

    sigemptyset(&sa_new.sa_mask);   // Clear mask
    sa_new.sa_flags = 0;            // No special flags
    sigaction(signo,&sa_new,&sa_old); // Set handler
}

Generated by  Doxygen 1.6.0   Back to index