1 kumpf 1.8 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
|
5 mike 1.2 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
|
12 kumpf 1.8 //
|
13 mike 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
16 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 //==============================================================================
23 //
|
24 kumpf 1.14 // Author: Markus Mueller (markus_mueller@de.ibm.com)
|
25 mike 1.2 //
|
26 kumpf 1.14 // Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
27 mike 1.2 //
28 //%/////////////////////////////////////////////////////////////////////////////
29
|
30 kumpf 1.14 #include <cstdio>
31 #include <cstring>
|
32 mday 1.14.6.1 #ifdef PEGASUS_PLATFORM_SOLARIS_SPARC_CC
33 #include <stdio.h>
34 #endif
|
35 kumpf 1.14
|
36 mike 1.2 #include <Pegasus/Common/Config.h>
37 #include <Pegasus/Common/Signal.h>
38
|
39 kumpf 1.14 PEGASUS_USING_PEGASUS;
40
41 void sig_act(int s_n, PEGASUS_SIGINFO_T * s_info, void * sig)
|
42 mike 1.2 {
|
43 kumpf 1.14 PEGASUS_THREAD_RETURN retval = 0;
|
44 mike 1.2
|
45 kumpf 1.14 if (s_n == PEGASUS_SIGABRT)
46 {
47 printf("Received an abort signal\n");
48 #ifdef PEGASUS_HAS_SIGNALS
49 printf(" in address %p\n", s_info->si_addr);
|
50 chuck 1.12 #endif
|
51 mike 1.2
|
52 kumpf 1.14 // In general it is dangerous to call pthread from within a
53 // signal handler, because they are not signal safe
54 exit_thread(retval);
55 }
|
56 mike 1.2 }
57
58
|
59 kumpf 1.14 PEGASUS_NAMESPACE_BEGIN
|
60 mike 1.2
|
61 kumpf 1.14 #ifdef PEGASUS_HAS_SIGNALS
|
62 mike 1.2
63 SignalHandler::SignalHandler() : reg_mutex()
64 {
65 for(Uint32 i=0;i < 32;i++)
66 {
67 reg_handler[i].active = 0;
68 reg_handler[i].sh = NULL;
69 memset(®_handler[i].oldsa,0,sizeof(struct sigaction));
70 }
71 }
72
73 SignalHandler::~SignalHandler()
74 {
75 deactivateAll();
76 }
77
78 void SignalHandler::registerHandler(Uint32 signum, signal_handler _sighandler)
79 {
|
80 sage 1.4 reg_mutex.lock(pegasus_thread_self());
|
81 mike 1.2 deactivate_i(signum);
82 reg_handler[signum].sh = _sighandler;
83 reg_mutex.unlock();
84 }
85
86 void SignalHandler::activate(Uint32 signum)
87 {
|
88 sage 1.4 reg_mutex.lock(pegasus_thread_self());
|
89 mike 1.2 if (reg_handler[signum].active) return; // throw exception
90
91 struct sigaction * sig_acts = new struct sigaction;
92
93 sig_acts->sa_sigaction = reg_handler[signum].sh;
94 sigfillset(&(sig_acts->sa_mask));
|
95 mday 1.14.6.1 #if defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_PLATFORM_HPUX_ACC) || defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM) || defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC)
|
96 sage 1.3 sig_acts->sa_flags = SA_SIGINFO | SA_RESETHAND;
97 #else
|
98 mike 1.2 sig_acts->sa_flags = SA_SIGINFO | SA_ONESHOT;
|
99 kumpf 1.6 #if !defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
|
100 mike 1.2 sig_acts->sa_restorer = NULL;
|
101 kumpf 1.5 #endif
|
102 sage 1.3 #endif
|
103 mike 1.2
104 sigaction(signum, sig_acts, ®_handler[signum].oldsa);
105
106 reg_handler[signum].active = -1;
107 reg_mutex.unlock();
108
109 delete sig_acts;
110 }
111
112 void SignalHandler::deactivate(Uint32 signum)
113 {
|
114 sage 1.4 reg_mutex.lock(pegasus_thread_self());
|
115 mike 1.2 deactivate_i(signum);
116 reg_mutex.unlock();
117 }
118
119 void SignalHandler::deactivate_i(Uint32 signum)
120 {
121 if (reg_handler[signum].active)
122 {
123 reg_handler[signum].active = 0;
124 sigaction(signum, ®_handler[signum].oldsa, NULL);
125 }
126 }
127
128 void SignalHandler::deactivateAll()
129 {
|
130 sage 1.4 reg_mutex.lock(pegasus_thread_self());
|
131 mike 1.2 for (Uint32 i=0; i < 32; i++)
132 if (reg_handler[i].active) deactivate_i(i);
133 reg_mutex.unlock();
134 }
135
136 void SignalHandler::ignore(Uint32 signum)
137 {
|
138 chuck 1.12 #if !defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)
|
139 mike 1.2 ::sigignore(signum);
|
140 chuck 1.12 #else
141 struct sigaction * sig_acts = new struct sigaction;
142
143 sig_acts->sa_handler = SIG_IGN;
144 sigfillset(&(sig_acts->sa_mask));
145 sig_acts->sa_flags = 0;
146
147 sigaction(signum, sig_acts, NULL);
148
149 delete sig_acts;
150 #endif
|
151 mike 1.2 }
|
152 kumpf 1.14
153 #else // PEGASUS_HAS_SIGNALS
154
155 SignalHandler::SignalHandler() { }
156
157 SignalHandler::~SignalHandler() { }
158
159 void SignalHandler::registerHandler(Uint32 signum, signal_handler _sighandler)
160 { }
161
162 void SignalHandler::activate(Uint32 signum) { }
163
164 void SignalHandler::deactivate(Uint32 signum) { }
165
166 void SignalHandler::deactivateAll() { }
167
168 void SignalHandler::ignore(Uint32 signum) { }
169
170 #endif // PEGASUS_HAS_SIGNALS
|
171 mike 1.2
172
173 // export the global signal handling object
174
175 SignalHandler _globalSignalHandler;
176 SignalHandler * _globalSignalHandlerPtr = &_globalSignalHandler;
177 SignalHandler * getSigHandle() { return _globalSignalHandlerPtr; }
178
179
180 PEGASUS_NAMESPACE_END
181
|