/*
*========================================================================
*
*   SYSTEM   : AZN_PLAZA_LANE LIBRARY
*   FILE     : lb_signal.sc
*   Progrmer : JBY (baarong@neighbor21.co.kr)
*   Date     : 2018.09.05
*   Modified :
*   Remark   :  시스템 시그널 Hooking.
 *              
 *========================================================================
*/

#include <signal.h>
#include "lb_func_list.h"

/*
 *========================================================================== 
 * signal hook function set 
 * return : void
 *==========================================================================
*/

/*
 *========================================================================
 *
 *   Function : signalSet()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2018.09.05
 *   Modified :
 *   Remark   :
 *
 *========================================================================
*/

void  signalSet (func)
void (*func) ();
{
    int i;

    for (i = 1; i < 64; i ++) signal (i, func);

    signal (SIGHUP,    func);   /* 1 ... hangup */
    signal (SIGINT,    func);   /* 2 ... interrupt (rubout) */
    signal (SIGQUIT,   func);   /* 3 ... quit (ASCII FS) */
    signal (SIGILL,    func);   /* 4 ... illegal instruction */
    signal (SIGTRAP,   func);   /* 5 ... trace trap */
    signal (SIGABRT,   func);   /* 6 ... used by abort, replace SIGIOT in the future */
#if 0
    signal (SIGEMT,    func);   /* 7 ... EMT instruction */
#endif
    signal (SIGFPE,    func);   /* 8 ... floating point exception */
    signal (SIGBUS,    func);   /* 10 .. bus error */
    signal (SIGSEGV,   func);   /* 11 .. segmentation violation */
    signal (SIGSYS,    func);   /* 12 .. bad argument to system call */
    signal (SIGPIPE,   func);   /* 13 .. write on a pipe with no one to read it */
    signal (SIGALRM,   func);   /* 14 .. alarm clock */
    signal (SIGTERM,   func);   /* 15 .. software termination signal from kill */
    signal (SIGUSR1,   func);   /* 16 .. user defined signal 1 */
    signal (SIGUSR2,   func);   /* 17 .. user defined signal 2 */
    signal (SIGCHLD,   func);   /* 18 .. child status change alias (POSIX) */
    signal (SIGPWR,    func);   /* 19 .. power-fail restart */
    signal (SIGVTALRM, func);   /* 20 .. virtual timer alarm */
    signal (SIGPROF,   func);   /* 21 .. profiling timer expired */
    signal (SIGIO,     func);   /* 22 .. asynchronous I/O */
    signal (SIGWINCH,  func);   /* 23 .. window size change signal */
    signal (SIGSTOP,   func);   /* 24 .. Stop signal (cannot be caught or ignore) */
    signal (SIGTSTP,   func);   /* 25 .. Interactive stop signal */
    signal (SIGCONT,   func);   /* 26 .. Continue if stopped */
    signal (SIGTTIN,   func);   /* 27 .. Read From control terminal ... */
    signal (SIGTTOU,   func);   /* 28 .. Write to control termial ... */
    signal (SIGURG,    func);   /* 29 .. virtual timer expired */
#if 0
    signal (SIGLOST,   func);   /* 30 .. remote lock lost (NFS) */
#endif
}

#ifdef _DEBUG_LIB
void sigset (sig)
{
    switch (sig)
    {
        default :
            printf ("[%d]\n", sig);
            exit (0);
    }
}

void main()
{
    lSignalSet (sigset);
    while (1) pause ();
}
#endif
