(file) Return to Signal.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  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            
 33 mike  1.2  #include <Pegasus/Common/Config.h>
 34            #include <Pegasus/Common/Signal.h>
 35            
 36 kumpf 1.14 PEGASUS_USING_PEGASUS;
 37            
 38            void sig_act(int s_n, PEGASUS_SIGINFO_T * s_info, void * sig)
 39 mike  1.2  {
 40 kumpf 1.14     PEGASUS_THREAD_RETURN retval = 0;
 41 mike  1.2  
 42 kumpf 1.14     if (s_n == PEGASUS_SIGABRT)
 43                {
 44                    printf("Received an abort signal\n");
 45            #ifdef PEGASUS_HAS_SIGNALS
 46                    printf(" in address %p\n", s_info->si_addr);
 47 chuck 1.12 #endif
 48 mike  1.2  
 49 kumpf 1.14         // In general it is dangerous to call pthread from within a
 50                    // signal handler, because they are not signal safe
 51                    exit_thread(retval);
 52                }
 53 mike  1.2  }
 54            
 55            
 56 kumpf 1.14 PEGASUS_NAMESPACE_BEGIN
 57 mike  1.2  
 58 kumpf 1.14 #ifdef PEGASUS_HAS_SIGNALS
 59 mike  1.2  
 60            SignalHandler::SignalHandler() : reg_mutex()
 61            {
 62               for(Uint32 i=0;i < 32;i++)
 63               {
 64                   reg_handler[i].active = 0;
 65                   reg_handler[i].sh = NULL;
 66                   memset(&reg_handler[i].oldsa,0,sizeof(struct sigaction));
 67               }
 68            }
 69            
 70            SignalHandler::~SignalHandler()
 71            {
 72               deactivateAll();
 73            }
 74            
 75            void SignalHandler::registerHandler(Uint32 signum, signal_handler _sighandler)
 76            {
 77 sage  1.4      reg_mutex.lock(pegasus_thread_self());
 78 mike  1.2      deactivate_i(signum);
 79                reg_handler[signum].sh = _sighandler;
 80                reg_mutex.unlock();
 81            }
 82            
 83            void SignalHandler::activate(Uint32 signum)
 84            {
 85 sage  1.4      reg_mutex.lock(pegasus_thread_self());
 86 mike  1.2      if (reg_handler[signum].active) return; // throw exception
 87            
 88                struct sigaction * sig_acts = new struct sigaction;
 89            
 90                sig_acts->sa_sigaction = reg_handler[signum].sh;
 91                sigfillset(&(sig_acts->sa_mask));
 92 kumpf 1.13 #if defined(PEGASUS_PLATFORM_AIX_RS_IBMCXX) || defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM) || defined(PEGASUS_PLATFORM_HPUX_ACC) || defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)
 93 sage  1.3      sig_acts->sa_flags = SA_SIGINFO | SA_RESETHAND;
 94            #else
 95 mike  1.2      sig_acts->sa_flags = SA_SIGINFO | SA_ONESHOT;
 96 kumpf 1.6  #if !defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU)
 97 mike  1.2      sig_acts->sa_restorer = NULL;
 98 kumpf 1.5  #endif
 99 sage  1.3  #endif
100 mike  1.2  
101                sigaction(signum, sig_acts, &reg_handler[signum].oldsa);
102            
103                reg_handler[signum].active = -1;
104                reg_mutex.unlock();
105            
106                delete sig_acts;
107            }
108            
109            void SignalHandler::deactivate(Uint32 signum)
110            {
111 sage  1.4      reg_mutex.lock(pegasus_thread_self());
112 mike  1.2      deactivate_i(signum);
113                reg_mutex.unlock();
114            }
115            
116            void SignalHandler::deactivate_i(Uint32 signum)
117            {
118                if (reg_handler[signum].active)
119                {
120                    reg_handler[signum].active = 0;
121                    sigaction(signum, &reg_handler[signum].oldsa, NULL);
122                }
123            }
124            
125            void SignalHandler::deactivateAll()
126            {
127 sage  1.4      reg_mutex.lock(pegasus_thread_self());
128 mike  1.2      for (Uint32 i=0; i < 32; i++)
129                    if (reg_handler[i].active) deactivate_i(i);
130                reg_mutex.unlock();
131            }
132            
133            void SignalHandler::ignore(Uint32 signum)
134            {
135 chuck 1.12 #if !defined(PEGASUS_PLATFORM_OS400_ISERIES_IBM)
136 mike  1.2      ::sigignore(signum);
137 chuck 1.12 #else
138                struct sigaction * sig_acts = new struct sigaction;
139            
140                sig_acts->sa_handler = SIG_IGN;
141                sigfillset(&(sig_acts->sa_mask));
142                sig_acts->sa_flags = 0;
143            
144                sigaction(signum, sig_acts, NULL);
145            
146                delete sig_acts;	
147            #endif
148 mike  1.2  }
149 kumpf 1.14 
150            #else // PEGASUS_HAS_SIGNALS
151            
152            SignalHandler::SignalHandler() { }
153            
154            SignalHandler::~SignalHandler() { }
155            
156            void SignalHandler::registerHandler(Uint32 signum, signal_handler _sighandler)
157            { }
158            
159            void SignalHandler::activate(Uint32 signum) { }
160            
161            void SignalHandler::deactivate(Uint32 signum) { }
162            
163            void SignalHandler::deactivateAll() { }
164            
165            void SignalHandler::ignore(Uint32 signum) { }
166            
167            #endif // PEGASUS_HAS_SIGNALS
168 mike  1.2  
169            
170            // export the global signal handling object
171            
172            SignalHandler _globalSignalHandler;
173            SignalHandler * _globalSignalHandlerPtr = &_globalSignalHandler;
174            SignalHandler * getSigHandle() { return _globalSignalHandlerPtr; }
175            
176            
177            PEGASUS_NAMESPACE_END
178            

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2