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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2