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

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

MAJ commentaires documentation pour doxygen - Reza 9 Juin 2005

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