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