[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"
|
---|
[480] | 7 | #include "pexceptions.h"
|
---|
[219] | 8 |
|
---|
[480] | 9 | static bool sigprstate[6] = {false, false, false, false, false, false};
|
---|
[241] | 10 |
|
---|
[913] | 11 | void SophyaProcessSignal(int s);
|
---|
[219] | 12 |
|
---|
| 13 | /* Nouvelle-Fonction */
|
---|
[913] | 14 | /*!\ingroup SysTools
|
---|
[2598] | 15 | \brief Utility function for signal handling configuration.
|
---|
| 16 |
|
---|
[913] | 17 | Configures signal handling. When the flag is true, an exception
|
---|
| 18 | \b CaughtSignalExc is thrown with the excpetion id set to the
|
---|
| 19 | signal id. With the flag is false, the default signal handling
|
---|
| 20 | is restored.
|
---|
| 21 | \param cfpe : Floating point exception \c SIGFPE
|
---|
| 22 | \param csegv : Segmentation fault \c SIGSEGV
|
---|
| 23 | \param cint : Interrupt signal \c SIGINT
|
---|
| 24 | \param cquit : Quit signal \c SIGINT
|
---|
| 25 | \param cusr1 : User signal 1 \c SIGUSR1
|
---|
| 26 | \param cusr2 : User signal 1 \c SIGUSR2
|
---|
| 27 | */
|
---|
| 28 | void SOPHYA::SophyaConfigureSignalhandling(bool cfpe, bool csegv, bool cint, bool cquit, bool cusr1, bool cusr2)
|
---|
[219] | 29 | {
|
---|
| 30 | struct sigaction ae, ad;
|
---|
| 31 |
|
---|
[913] | 32 | ae.sa_handler = SophyaProcessSignal;
|
---|
[219] | 33 | ad.sa_handler = SIG_DFL;
|
---|
| 34 | memset( &(ae.sa_mask), 0, sizeof(sigset_t) );
|
---|
| 35 | ae.sa_flags = 0;
|
---|
| 36 | memset( &(ad.sa_mask), 0, sizeof(sigset_t) );
|
---|
| 37 | ad.sa_flags = 0;
|
---|
| 38 | #ifdef OSF1
|
---|
| 39 | ae.sa_flags = SA_RESTART;
|
---|
| 40 | ad.sa_mask = 0;
|
---|
| 41 | #endif
|
---|
| 42 |
|
---|
| 43 | // SIGFPE
|
---|
| 44 | if (sigprstate[0] != cfpe) {
|
---|
| 45 | if (cfpe) {
|
---|
| 46 | sigaction(SIGFPE, &ae, NULL);
|
---|
[913] | 47 | puts("SophyaConfigureSignalhandling(): Activating SIGFPE handling (-> throw) ...");
|
---|
[219] | 48 | }
|
---|
| 49 | else {
|
---|
| 50 | sigaction(SIGFPE, &ad, NULL);
|
---|
[913] | 51 | puts("SophyaConfigureSignalhandling(): Back to default SIGFPE handling ...");
|
---|
[219] | 52 | }
|
---|
| 53 | sigprstate[0] = cfpe;
|
---|
| 54 | }
|
---|
| 55 | // SIGSEGV
|
---|
| 56 | if (sigprstate[1] != csegv) {
|
---|
| 57 | if (csegv) {
|
---|
| 58 | sigaction(SIGSEGV, &ae, NULL);
|
---|
[913] | 59 | puts("SophyaConfigureSignalhandling(): Activating SIGSEGV handling (-> throw) ...");
|
---|
[219] | 60 | }
|
---|
| 61 | else {
|
---|
| 62 | sigaction(SIGSEGV, &ad, NULL);
|
---|
[913] | 63 | puts("SophyaConfigureSignalhandling(): Back to default SIGSEGV handling ...");
|
---|
[219] | 64 | }
|
---|
| 65 | sigprstate[1] = csegv;
|
---|
| 66 | }
|
---|
[480] | 67 |
|
---|
| 68 | // SIGINT
|
---|
| 69 | if (sigprstate[2] != cint) {
|
---|
[706] | 70 | if (cint) {
|
---|
[480] | 71 | sigaction(SIGINT, &ae, NULL);
|
---|
[913] | 72 | puts("SophyaConfigureSignalhandling(): Activating SIGINT handling (-> throw) ...");
|
---|
[480] | 73 | }
|
---|
| 74 | else {
|
---|
| 75 | sigaction(SIGINT, &ad, NULL);
|
---|
[913] | 76 | puts("SophyaConfigureSignalhandling(): Back to default SIGINT handling ...");
|
---|
[480] | 77 | }
|
---|
| 78 | sigprstate[2] = cint;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[219] | 81 | // SIGQUIT
|
---|
[480] | 82 | if (sigprstate[3] != cquit) {
|
---|
[219] | 83 | if (cquit) {
|
---|
| 84 | sigaction(SIGQUIT, &ae, NULL);
|
---|
[913] | 85 | puts("SophyaConfigureSignalhandling(): Activating SIGQUIT handling (-> throw) ...");
|
---|
[219] | 86 | }
|
---|
| 87 | else {
|
---|
| 88 | sigaction(SIGQUIT, &ad, NULL);
|
---|
[913] | 89 | puts("SophyaConfigureSignalhandling(): Back to default SIGQUIT handling ...");
|
---|
[219] | 90 | }
|
---|
[480] | 91 | sigprstate[3] = cquit;
|
---|
[219] | 92 | }
|
---|
| 93 |
|
---|
| 94 | // SIGUSR1
|
---|
[480] | 95 | if (sigprstate[4] != cusr1) {
|
---|
[219] | 96 | if (cusr1) {
|
---|
| 97 | sigaction(SIGUSR1, &ae, NULL);
|
---|
[913] | 98 | puts("SophyaConfigureSignalhandling(): Activating SIGUSR1 handling (-> throw) ...");
|
---|
[219] | 99 | }
|
---|
| 100 | else {
|
---|
| 101 | sigaction(SIGUSR1, &ad, NULL);
|
---|
[913] | 102 | puts("SophyaConfigureSignalhandling(): Back to default SIGUSR1 handling ...");
|
---|
[219] | 103 | }
|
---|
[480] | 104 | sigprstate[4] = cusr1;
|
---|
[219] | 105 | }
|
---|
[480] | 106 | // SIGUSR2
|
---|
| 107 | if (sigprstate[5] != cusr2) {
|
---|
[219] | 108 | if (cusr2) {
|
---|
| 109 | sigaction(SIGUSR2, &ae, NULL);
|
---|
[913] | 110 | puts("SophyaConfigureSignalhandling(): Activating SIGUSR2 handling (-> throw) ...");
|
---|
[219] | 111 | }
|
---|
| 112 | else {
|
---|
| 113 | sigaction(SIGUSR2, &ad, NULL);
|
---|
[913] | 114 | puts("SophyaConfigureSignalhandling(): Back to default SIGUSR2 handling ...");
|
---|
[219] | 115 | }
|
---|
[480] | 116 | sigprstate[5] = cusr2;
|
---|
[219] | 117 | }
|
---|
| 118 | }
|
---|
| 119 | /* Nouvelle-Fonction */
|
---|
[913] | 120 | void SophyaProcessSignal(int s)
|
---|
[219] | 121 | {
|
---|
[480] | 122 | string msg;
|
---|
[219] | 123 | switch(s)
|
---|
| 124 | {
|
---|
| 125 | case SIGFPE :
|
---|
[913] | 126 | puts("SophyaProcessSignal: ###Signal SIGFPE catched, throw catchedSIGFPE ###");
|
---|
[480] | 127 | msg = "Caught SIGFPE";
|
---|
| 128 | throw ( CaughtSignalExc(msg, s) );
|
---|
[219] | 129 | case SIGSEGV :
|
---|
[913] | 130 | puts("SophyaProcessSignal: ###Signal SIGSEGV catched, throw catchedSIGSEGV ###");
|
---|
[480] | 131 | msg = "Caught SIGSEGV";
|
---|
| 132 | throw ( CaughtSignalExc(msg, s) );
|
---|
[219] | 133 | case SIGINT :
|
---|
[913] | 134 | puts("SophyaProcessSignal: ###Signal SIGINT catched, throw catchedSIGINT ###");
|
---|
[480] | 135 | msg = "Caught SIGINT";
|
---|
| 136 | throw ( CaughtSignalExc(msg, s) );
|
---|
[219] | 137 | case SIGQUIT :
|
---|
[913] | 138 | puts("SophyaProcessSignal: ###Signal SIGQUIT catched, throw catchedSIGQUIT ###");
|
---|
[480] | 139 | msg = "Caught SIGQUIT";
|
---|
| 140 | throw ( CaughtSignalExc(msg, s) );
|
---|
[219] | 141 | case SIGUSR1 :
|
---|
[913] | 142 | puts("SophyaProcessSignal: ###Signal SIGUSR1 catched, throw catchedSIGUSR1 ###");
|
---|
[480] | 143 | msg = "Caught SIGUSR1";
|
---|
| 144 | throw ( CaughtSignalExc(msg, s) );
|
---|
[219] | 145 | case SIGUSR2 :
|
---|
[913] | 146 | puts("SophyaProcessSignal: ###Signal SIGUSR2 catched, throw catchedSIGUSR2 ###");
|
---|
[480] | 147 | msg = "Caught SIGUSR2";
|
---|
| 148 | throw ( CaughtSignalExc(msg, s) );
|
---|
[219] | 149 | default :
|
---|
[2508] | 150 | printf("SophyaProcessSignal: ###Signal %d catched, throw Caught SIG??? ### \n", s);
|
---|
[480] | 151 | msg = "Caught SIG???";
|
---|
| 152 | throw ( CaughtSignalExc(msg, s) );
|
---|
[219] | 153 | }
|
---|
[480] | 154 |
|
---|
| 155 | // return;
|
---|
[219] | 156 | }
|
---|