[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"
|
---|
| 7 | #include "perrors.h"
|
---|
| 8 |
|
---|
| 9 | static bool sigprstate[5] = {false, false, false, false};
|
---|
| 10 |
|
---|
| 11 | void PeidaProcessSignal(int s);
|
---|
| 12 |
|
---|
| 13 | /* Nouvelle-Fonction */
|
---|
| 14 | void PeidaConfigureSignalhandling(bool cfpe, bool csegv, 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 | // SIGQUIT
|
---|
| 54 | if (sigprstate[2] != cquit) {
|
---|
| 55 | if (cquit) {
|
---|
| 56 | sigaction(SIGQUIT, &ae, NULL);
|
---|
| 57 | puts("PeidaConfigureSignalhandling(): Activating SIGQUIT handling (-> throw) ...");
|
---|
| 58 | }
|
---|
| 59 | else {
|
---|
| 60 | sigaction(SIGQUIT, &ad, NULL);
|
---|
| 61 | puts("PeidaConfigureSignalhandling(): Back to default SIGQUIT handling ...");
|
---|
| 62 | }
|
---|
| 63 | sigprstate[2] = cquit;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | // SIGUSR1
|
---|
| 67 | if (sigprstate[3] != cusr1) {
|
---|
| 68 | if (cusr1) {
|
---|
| 69 | sigaction(SIGUSR1, &ae, NULL);
|
---|
| 70 | puts("PeidaConfigureSignalhandling(): Activating SIGUSR1 handling (-> throw) ...");
|
---|
| 71 | }
|
---|
| 72 | else {
|
---|
| 73 | sigaction(SIGUSR1, &ad, NULL);
|
---|
| 74 | puts("PeidaConfigureSignalhandling(): Back to default SIGUSR1 handling ...");
|
---|
| 75 | }
|
---|
| 76 | sigprstate[3] = cusr1;
|
---|
| 77 | }
|
---|
| 78 | // SIGUSR1
|
---|
| 79 | if (sigprstate[4] != cusr2) {
|
---|
| 80 | if (cusr2) {
|
---|
| 81 | sigaction(SIGUSR2, &ae, NULL);
|
---|
| 82 | puts("PeidaConfigureSignalhandling(): Activating SIGUSR2 handling (-> throw) ...");
|
---|
| 83 | }
|
---|
| 84 | else {
|
---|
| 85 | sigaction(SIGUSR2, &ad, NULL);
|
---|
| 86 | puts("PeidaConfigureSignalhandling(): Back to default SIGUSR2 handling ...");
|
---|
| 87 | }
|
---|
| 88 | sigprstate[4] = cusr2;
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | /* Nouvelle-Fonction */
|
---|
| 92 | void PeidaProcessSignal(int s)
|
---|
| 93 | {
|
---|
| 94 | switch(s)
|
---|
| 95 | {
|
---|
| 96 | case SIGFPE :
|
---|
| 97 | puts("PeidaProcessSignal: ###Signal SIGFPE catched, throw catchedSIGFPE ###");
|
---|
| 98 | THROW(catchedSIGFPE);
|
---|
| 99 | case SIGSEGV :
|
---|
| 100 | puts("PeidaProcessSignal: ###Signal SIGSEGV catched, throw catchedSIGSEGV ###");
|
---|
| 101 | THROW(catchedSIGSEGV);
|
---|
| 102 | case SIGINT :
|
---|
| 103 | puts("PeidaProcessSignal: ###Signal SIGINT catched, throw catchedSIGINT ###");
|
---|
| 104 | THROW(catchedSIGINT);
|
---|
| 105 | case SIGQUIT :
|
---|
| 106 | puts("PeidaProcessSignal: ###Signal SIGQUIT catched, throw catchedSIGQUIT ###");
|
---|
| 107 | THROW(catchedSIGQUIT);
|
---|
| 108 | case SIGUSR1 :
|
---|
| 109 | puts("PeidaProcessSignal: ###Signal SIGUSR1 catched, throw catchedSIGUSR1 ###");
|
---|
| 110 | THROW(catchedSIGQUIT);
|
---|
| 111 | case SIGUSR2 :
|
---|
| 112 | puts("PeidaProcessSignal: ###Signal SIGUSR2 catched, throw catchedSIGUSR2 ###");
|
---|
| 113 | THROW(catchedSIGQUIT);
|
---|
| 114 | default :
|
---|
| 115 | printf("PeidaProcessSignal: ###Signal %d catched, throw inconsistentErr ### \n", s);
|
---|
| 116 | THROW(inconsistentErr);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | return;
|
---|
| 120 | }
|
---|