[219] | 1 | // Pour la gestion des signaux a travers des exceptions
|
---|
| 2 | #include <stdlib.h>
|
---|
| 3 | #include <stdio.h>
|
---|
| 4 | #include <string.h>
|
---|
| 5 | #include <signal.h>
|
---|
| 6 | #include "psighand.h"
|
---|
[241] | 7 | #include "pexceptions.h"
|
---|
[219] | 8 |
|
---|
[241] | 9 | using namespace PlanckDPC;
|
---|
| 10 |
|
---|
[219] | 11 | static bool sigprstate[5] = {false, false, false, false};
|
---|
| 12 |
|
---|
| 13 | void PeidaProcessSignal(int s);
|
---|
| 14 |
|
---|
| 15 | /* Nouvelle-Fonction */
|
---|
| 16 | void PeidaConfigureSignalhandling(bool cfpe, bool csegv, bool cquit, bool cusr1, bool cusr2)
|
---|
| 17 | {
|
---|
| 18 | struct sigaction ae, ad;
|
---|
| 19 |
|
---|
| 20 | ae.sa_handler = PeidaProcessSignal;
|
---|
| 21 | ad.sa_handler = SIG_DFL;
|
---|
| 22 | memset( &(ae.sa_mask), 0, sizeof(sigset_t) );
|
---|
| 23 | ae.sa_flags = 0;
|
---|
| 24 | memset( &(ad.sa_mask), 0, sizeof(sigset_t) );
|
---|
| 25 | ad.sa_flags = 0;
|
---|
| 26 | #ifdef OSF1
|
---|
| 27 | ae.sa_flags = SA_RESTART;
|
---|
| 28 | ad.sa_mask = 0;
|
---|
| 29 | #endif
|
---|
| 30 |
|
---|
| 31 | // SIGFPE
|
---|
| 32 | if (sigprstate[0] != cfpe) {
|
---|
| 33 | if (cfpe) {
|
---|
| 34 | sigaction(SIGFPE, &ae, NULL);
|
---|
| 35 | puts("PeidaConfigureSignalhandling(): Activating SIGFPE handling (-> throw) ...");
|
---|
| 36 | }
|
---|
| 37 | else {
|
---|
| 38 | sigaction(SIGFPE, &ad, NULL);
|
---|
| 39 | puts("PeidaConfigureSignalhandling(): Back to default SIGFPE handling ...");
|
---|
| 40 | }
|
---|
| 41 | sigprstate[0] = cfpe;
|
---|
| 42 | }
|
---|
| 43 | // SIGSEGV
|
---|
| 44 | if (sigprstate[1] != csegv) {
|
---|
| 45 | if (csegv) {
|
---|
| 46 | sigaction(SIGSEGV, &ae, NULL);
|
---|
| 47 | puts("PeidaConfigureSignalhandling(): Activating SIGSEGV handling (-> throw) ...");
|
---|
| 48 | }
|
---|
| 49 | else {
|
---|
| 50 | sigaction(SIGSEGV, &ad, NULL);
|
---|
| 51 | puts("PeidaConfigureSignalhandling(): Back to default SIGSEGV handling ...");
|
---|
| 52 | }
|
---|
| 53 | sigprstate[1] = csegv;
|
---|
| 54 | }
|
---|
| 55 | // SIGQUIT
|
---|
| 56 | if (sigprstate[2] != cquit) {
|
---|
| 57 | if (cquit) {
|
---|
| 58 | sigaction(SIGQUIT, &ae, NULL);
|
---|
| 59 | puts("PeidaConfigureSignalhandling(): Activating SIGQUIT handling (-> throw) ...");
|
---|
| 60 | }
|
---|
| 61 | else {
|
---|
| 62 | sigaction(SIGQUIT, &ad, NULL);
|
---|
| 63 | puts("PeidaConfigureSignalhandling(): Back to default SIGQUIT handling ...");
|
---|
| 64 | }
|
---|
| 65 | sigprstate[2] = cquit;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | // SIGUSR1
|
---|
| 69 | if (sigprstate[3] != cusr1) {
|
---|
| 70 | if (cusr1) {
|
---|
| 71 | sigaction(SIGUSR1, &ae, NULL);
|
---|
| 72 | puts("PeidaConfigureSignalhandling(): Activating SIGUSR1 handling (-> throw) ...");
|
---|
| 73 | }
|
---|
| 74 | else {
|
---|
| 75 | sigaction(SIGUSR1, &ad, NULL);
|
---|
| 76 | puts("PeidaConfigureSignalhandling(): Back to default SIGUSR1 handling ...");
|
---|
| 77 | }
|
---|
| 78 | sigprstate[3] = cusr1;
|
---|
| 79 | }
|
---|
| 80 | // SIGUSR1
|
---|
| 81 | if (sigprstate[4] != cusr2) {
|
---|
| 82 | if (cusr2) {
|
---|
| 83 | sigaction(SIGUSR2, &ae, NULL);
|
---|
| 84 | puts("PeidaConfigureSignalhandling(): Activating SIGUSR2 handling (-> throw) ...");
|
---|
| 85 | }
|
---|
| 86 | else {
|
---|
| 87 | sigaction(SIGUSR2, &ad, NULL);
|
---|
| 88 | puts("PeidaConfigureSignalhandling(): Back to default SIGUSR2 handling ...");
|
---|
| 89 | }
|
---|
| 90 | sigprstate[4] = cusr2;
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 | /* Nouvelle-Fonction */
|
---|
| 94 | void PeidaProcessSignal(int s)
|
---|
| 95 | {
|
---|
| 96 | switch(s)
|
---|
| 97 | {
|
---|
| 98 | case SIGFPE :
|
---|
| 99 | puts("PeidaProcessSignal: ###Signal SIGFPE catched, throw catchedSIGFPE ###");
|
---|
[241] | 100 | throw CaughtSignalExc("SIGFPE");
|
---|
[219] | 101 | case SIGSEGV :
|
---|
| 102 | puts("PeidaProcessSignal: ###Signal SIGSEGV catched, throw catchedSIGSEGV ###");
|
---|
[241] | 103 | throw CaughtSignalExc("SIGSEGV");
|
---|
[219] | 104 | case SIGINT :
|
---|
| 105 | puts("PeidaProcessSignal: ###Signal SIGINT catched, throw catchedSIGINT ###");
|
---|
[241] | 106 | throw CaughtSignalExc("SIGINT");
|
---|
[219] | 107 | case SIGQUIT :
|
---|
| 108 | puts("PeidaProcessSignal: ###Signal SIGQUIT catched, throw catchedSIGQUIT ###");
|
---|
[241] | 109 | throw CaughtSignalExc("SIGQUIT");
|
---|
[219] | 110 | case SIGUSR1 :
|
---|
| 111 | puts("PeidaProcessSignal: ###Signal SIGUSR1 catched, throw catchedSIGUSR1 ###");
|
---|
[241] | 112 | throw CaughtSignalExc("SIGUSR1");
|
---|
[219] | 113 | case SIGUSR2 :
|
---|
| 114 | puts("PeidaProcessSignal: ###Signal SIGUSR2 catched, throw catchedSIGUSR2 ###");
|
---|
[241] | 115 | throw CaughtSignalExc("SIGUSR2");
|
---|
[219] | 116 | default :
|
---|
| 117 | printf("PeidaProcessSignal: ###Signal %d catched, throw inconsistentErr ### \n", s);
|
---|
[241] | 118 | throw CaughtSignalExc("???");
|
---|
[219] | 119 | }
|
---|
| 120 | }
|
---|