source: Sophya/trunk/SophyaLib/SysTools/psighand.cc@ 656

Last change on this file since 656 was 480, checked in by ansari, 26 years ago

MAJ / PEIDA 3.8 , Reza 20/10/99

File size: 4.1 KB
RevLine 
[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]9static bool sigprstate[6] = {false, false, false, false, false, false};
[241]10
[219]11void PeidaProcessSignal(int s);
12
13/* Nouvelle-Fonction */
[480]14void PeidaConfigureSignalhandling(bool cfpe, bool csegv, bool cint, bool cquit, bool cusr1, bool cusr2)
[219]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 }
[480]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
[219]67// SIGQUIT
[480]68 if (sigprstate[3] != cquit) {
[219]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 }
[480]77 sigprstate[3] = cquit;
[219]78 }
79
80// SIGUSR1
[480]81 if (sigprstate[4] != cusr1) {
[219]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 }
[480]90 sigprstate[4] = cusr1;
[219]91 }
[480]92// SIGUSR2
93 if (sigprstate[5] != cusr2) {
[219]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 }
[480]102 sigprstate[5] = cusr2;
[219]103 }
104}
105/* Nouvelle-Fonction */
106void PeidaProcessSignal(int s)
107{
[480]108string msg;
[219]109switch(s)
110 {
111 case SIGFPE :
112 puts("PeidaProcessSignal: ###Signal SIGFPE catched, throw catchedSIGFPE ###");
[480]113 msg = "Caught SIGFPE";
114 throw ( CaughtSignalExc(msg, s) );
[219]115 case SIGSEGV :
116 puts("PeidaProcessSignal: ###Signal SIGSEGV catched, throw catchedSIGSEGV ###");
[480]117 msg = "Caught SIGSEGV";
118 throw ( CaughtSignalExc(msg, s) );
[219]119 case SIGINT :
120 puts("PeidaProcessSignal: ###Signal SIGINT catched, throw catchedSIGINT ###");
[480]121 msg = "Caught SIGINT";
122 throw ( CaughtSignalExc(msg, s) );
[219]123 case SIGQUIT :
124 puts("PeidaProcessSignal: ###Signal SIGQUIT catched, throw catchedSIGQUIT ###");
[480]125 msg = "Caught SIGQUIT";
126 throw ( CaughtSignalExc(msg, s) );
[219]127 case SIGUSR1 :
128 puts("PeidaProcessSignal: ###Signal SIGUSR1 catched, throw catchedSIGUSR1 ###");
[480]129 msg = "Caught SIGUSR1";
130 throw ( CaughtSignalExc(msg, s) );
[219]131 case SIGUSR2 :
132 puts("PeidaProcessSignal: ###Signal SIGUSR2 catched, throw catchedSIGUSR2 ###");
[480]133 msg = "Caught SIGUSR2";
134 throw ( CaughtSignalExc(msg, s) );
[219]135 default :
136 printf("PeidaProcessSignal: ###Signal %d catched, throw inconsistentErr ### \n", s);
[480]137 msg = "Caught SIG???";
138 throw ( CaughtSignalExc(msg, s) );
[219]139 }
[480]140
141// return;
[219]142}
Note: See TracBrowser for help on using the repository browser.