help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

signal handling in octave


From: Joao Cardoso
Subject: signal handling in octave
Date: Wed, 03 Jun 1998 20:35:46 +0100

Hi,

I need octave to handle signals comming from other processes, and
execute
a script or dll function.
I have implemented a simple minded octave C function, on_signal(SIG,
func)
that replaces the octave default handler on reception of signal SIG, it
`feval' string `func', that is the name of a script or builtin function.
It works pretty well when it works :). It worked OK in 2.0.12 but not
complely well in 2.0.13.

The problem must be that octave is interrupted when it is executing some
critical code. How can I detect, in my signal_handling routine, that the
octave interpreter must not be interrupted? Is it possible to
incorporate
in the octave main loop a call to some `is_any_signal_pending' ? Are
signals
blocked when dealing with critical sections?

The relevant section of code:


char ev[MAXSIG][40];            /* I should use a struct */
char ev_data[MAXSIG][40];
void *oev[MAXSIG];

extern octave_value_list Ffeval (const octave_value_list&, int);

/*
 * Called at signal "interrupt" time.
 * 
 * equivalent to `feval(proc, data)'
 */
   
void ev_proc(int sig)
{
    int i;
    octave_value_list find_args;
    
    find_args(0) = ev[sig];
    find_args(1) = ev_data[sig];
    
    Ffeval (find_args, i);
}
 
/*
 * Define which octave function (or script) to call on ocurrence
 * of signal `signal', and define a string argument to pass to function.
 * 
 * Possible values for the procedure to call are:
 * 
 *  the name of an Octave builtin/script function
 *  "SIG_IGN", to ignore signal
 *  "SIG_DFL", to process signal with system (UNIX) default behavior
 *  "OCT_DFL" or "" to restore Octave default handler
 * 
 * This can be improved. If used sa.sigaction instead of sa.handler,
 * The called function can discover why/from it was called;
 * see sigint(3) (AT&T SVID) and sigaction(3).
 */
   
void on_signal(int event, char *proc, char *data)
{
    struct sigaction act, oact;
    
    act.sa_mask = SIGALL;
    act.sa_flags = SA_RESTART | SA_NOCLDSTOP | SA_NOCLDSTOP;
    
    if (strcmp(proc, "SIG_IGN") == 0)
        act.sa_handler = SIG_IGN;
    else if (strcmp(proc, "SIG_DFL") == 0)
        act.sa_handler = SIG_DFL;
    else if (strlen(proc) == 0 || strcmp(proc, "OCT_DFL") == 0) {
        if (oev[event] != NULL)
            act.sa_handler = oev[event];
        else
            return;
    }
    else act.sa_handler = ev_proc;
    
    sigaction(event, &act, &oact);
    
    if (oev[event] == NULL)
        oev[event] = oact.sa_handler;
        
    strncpy(ev[event], proc, 40);
    strncpy(ev_data[event], data, 40);
}

Thanks,
Joao
-- 
Joao Cardoso                    |       e-mail: address@hidden
INESC, R. Jose Falcao 110       |       tel:    + 351 2 2094322
4000 PORTO, PORTUGAL            |       fax:    + 351 2 2008487



reply via email to

[Prev in Thread] Current Thread [Next in Thread]