// Pour la gestion des signaux a travers des exceptions #include #include #include #include #include "psighand.h" #include "pexceptions.h" using namespace PlanckDPC; static bool sigprstate[5] = {false, false, false, false}; void PeidaProcessSignal(int s); /* Nouvelle-Fonction */ void PeidaConfigureSignalhandling(bool cfpe, bool csegv, bool cquit, bool cusr1, bool cusr2) { struct sigaction ae, ad; ae.sa_handler = PeidaProcessSignal; ad.sa_handler = SIG_DFL; memset( &(ae.sa_mask), 0, sizeof(sigset_t) ); ae.sa_flags = 0; memset( &(ad.sa_mask), 0, sizeof(sigset_t) ); ad.sa_flags = 0; #ifdef OSF1 ae.sa_flags = SA_RESTART; ad.sa_mask = 0; #endif // SIGFPE if (sigprstate[0] != cfpe) { if (cfpe) { sigaction(SIGFPE, &ae, NULL); puts("PeidaConfigureSignalhandling(): Activating SIGFPE handling (-> throw) ..."); } else { sigaction(SIGFPE, &ad, NULL); puts("PeidaConfigureSignalhandling(): Back to default SIGFPE handling ..."); } sigprstate[0] = cfpe; } // SIGSEGV if (sigprstate[1] != csegv) { if (csegv) { sigaction(SIGSEGV, &ae, NULL); puts("PeidaConfigureSignalhandling(): Activating SIGSEGV handling (-> throw) ..."); } else { sigaction(SIGSEGV, &ad, NULL); puts("PeidaConfigureSignalhandling(): Back to default SIGSEGV handling ..."); } sigprstate[1] = csegv; } // SIGQUIT if (sigprstate[2] != cquit) { if (cquit) { sigaction(SIGQUIT, &ae, NULL); puts("PeidaConfigureSignalhandling(): Activating SIGQUIT handling (-> throw) ..."); } else { sigaction(SIGQUIT, &ad, NULL); puts("PeidaConfigureSignalhandling(): Back to default SIGQUIT handling ..."); } sigprstate[2] = cquit; } // SIGUSR1 if (sigprstate[3] != cusr1) { if (cusr1) { sigaction(SIGUSR1, &ae, NULL); puts("PeidaConfigureSignalhandling(): Activating SIGUSR1 handling (-> throw) ..."); } else { sigaction(SIGUSR1, &ad, NULL); puts("PeidaConfigureSignalhandling(): Back to default SIGUSR1 handling ..."); } sigprstate[3] = cusr1; } // SIGUSR1 if (sigprstate[4] != cusr2) { if (cusr2) { sigaction(SIGUSR2, &ae, NULL); puts("PeidaConfigureSignalhandling(): Activating SIGUSR2 handling (-> throw) ..."); } else { sigaction(SIGUSR2, &ad, NULL); puts("PeidaConfigureSignalhandling(): Back to default SIGUSR2 handling ..."); } sigprstate[4] = cusr2; } } /* Nouvelle-Fonction */ void PeidaProcessSignal(int s) { switch(s) { case SIGFPE : puts("PeidaProcessSignal: ###Signal SIGFPE catched, throw catchedSIGFPE ###"); throw CaughtSignalExc("SIGFPE"); case SIGSEGV : puts("PeidaProcessSignal: ###Signal SIGSEGV catched, throw catchedSIGSEGV ###"); throw CaughtSignalExc("SIGSEGV"); case SIGINT : puts("PeidaProcessSignal: ###Signal SIGINT catched, throw catchedSIGINT ###"); throw CaughtSignalExc("SIGINT"); case SIGQUIT : puts("PeidaProcessSignal: ###Signal SIGQUIT catched, throw catchedSIGQUIT ###"); throw CaughtSignalExc("SIGQUIT"); case SIGUSR1 : puts("PeidaProcessSignal: ###Signal SIGUSR1 catched, throw catchedSIGUSR1 ###"); throw CaughtSignalExc("SIGUSR1"); case SIGUSR2 : puts("PeidaProcessSignal: ###Signal SIGUSR2 catched, throw catchedSIGUSR2 ###"); throw CaughtSignalExc("SIGUSR2"); default : printf("PeidaProcessSignal: ###Signal %d catched, throw inconsistentErr ### \n", s); throw CaughtSignalExc("???"); } }