/* 
**
** Signal functions
**
*/

#include 	"../include/includes.h"

/*
** Set termination signal in a loop program, 
** handler of function mostly deal with something,
** e.g. closing file handler, socket handler or free allocatied memory.
*/
void
SetTermSignal(struct termio *ptermio, void (*handler)(int))
{
    ioctl(0, TCGETA, ptermio);
    ptermio->c_cc[VINTR] = '\x03';
    ioctl(0, TCSETA, ptermio);

    signal(SIGINT, handler);
    signal(SIGTERM, handler);
    signal(SIGSTOP, handler);
    signal(SIGKILL, handler);
    signal(SIGQUIT, handler);
    signal(SIGABRT, handler);
    signal(SIGHUP, handler);
}

void
SetFaultSignal(void (*handler)(int) )
{
    signal(SIGSEGV, handler);
}

void
SetRefreshSignal(struct termio *ptermio, void (*handler)(int))
{
    ioctl(0, TCGETA, ptermio);
    ptermio->c_cc[VQUIT] = '\x12';  /* QUIT: Ctrl+R */
    ioctl(0, TCSETA, ptermio);

    signal(SIGQUIT, handler);
}
