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

Last change on this file since 4054 was 2804, checked in by ansari, 20 years ago

MAJ commentaires documentation pour doxygen - Reza 9 Juin 2005

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