#include <Signal.h>
Inheritance diagram for ACE_Sig_Handlers:
Public Member Functions | |
virtual int | register_handler (int signum, ACE_Event_Handler *new_sh, ACE_Sig_Action *new_disp=0, ACE_Event_Handler **old_sh=0, ACE_Sig_Action *old_disp=0) |
virtual int | remove_handler (int signum, ACE_Sig_Action *new_disp=0, ACE_Sig_Action *old_disp=0, int sigkey=-1) |
virtual ACE_Event_Handler * | handler (int signum) |
virtual ACE_Event_Handler * | handler (int signum, ACE_Event_Handler *) |
void | dump (void) const |
Dump the state of an object. | |
Static Public Member Functions | |
void | dispatch (int signum, siginfo_t *, ucontext_t *) |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Static Private Attributes | |
int | sigkey_ = 0 |
int | third_party_sig_handler_ = 0 |
Using this class a program can register one or more ACE_Event_Handler with the ACE_Sig_Handler in order to handle a designated . When a signal occurs that corresponds to this , the methods of all the registered ACE_Event_Handlers are invoked automatically.
Definition at line 440 of file Signal.h.
|
Callback routine registered with sigaction(2) that dispatches the method of all the pre-registered ACE_Event_Handlers for Reimplemented from ACE_Sig_Handler. Definition at line 809 of file Signal.cpp. References ACE_ASSERT, ACE_SIG_HANDLERS_ITERATOR, ACE_SIG_HANDLERS_SET, ACE_TRACE, ACE_Fixed_Set_Iterator_Base< T, ACE_SIZE >::advance(), ACE_Sig_Handlers_Set::instance(), ACE_Fixed_Set_Iterator< T, ACE_SIZE >::next(), ACE_Fixed_Set< T, ACE_SIZE >::remove(), and ucontext_t.
00812 { 00813 ACE_TRACE ("ACE_Sig_Handlers::dispatch"); 00814 // The following is #ifdef'd out because it's entirely non-portable 00815 // to acquire a mutex in a signal handler... 00816 #if 0 00817 ACE_MT (ACE_Recursive_Thread_Mutex *lock = 00818 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object 00819 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK); 00820 ACE_TSS_Guard<ACE_Recursive_Thread_Mutex> m (*lock)); 00821 #endif /* 0 */ 00822 00823 // Save/restore errno. 00824 ACE_Errno_Guard error (errno); 00825 00826 ACE_Sig_Handler::sig_pending_ = 1; 00827 00828 // Darn well better be in range since the OS dispatched this... 00829 ACE_ASSERT (ACE_Sig_Handler::in_range (signum)); 00830 00831 ACE_SIG_HANDLERS_SET *handler_set = 00832 ACE_Sig_Handlers_Set::instance (signum); 00833 00834 ACE_SIG_HANDLERS_ITERATOR handler_iterator (*handler_set); 00835 00836 for (ACE_Event_Handler **eh = 0; 00837 handler_iterator.next (eh) != 0; 00838 handler_iterator.advance ()) 00839 { 00840 if ((*eh)->handle_signal (signum, siginfo, ucontext) == -1) 00841 { 00842 handler_set->remove (*eh); 00843 delete *eh; 00844 } 00845 } 00846 } |
|
Dump the state of an object.
Reimplemented from ACE_Sig_Handler. Definition at line 612 of file Signal.cpp. References ACE_TRACE.
00613 { 00614 #if defined (ACE_HAS_DUMP) 00615 ACE_TRACE ("ACE_Sig_Handlers::dump"); 00616 #endif /* ACE_HAS_DUMP */ 00617 } |
|
Set a new ACE_Event_Handler that is associated with SIGNUM at the head of the list of signals. Return the existing handler that was at the head. Reimplemented from ACE_Sig_Handler. Definition at line 871 of file Signal.cpp. References ACE_NEW_RETURN, ACE_SIG_HANDLERS_ITERATOR, ACE_SIG_HANDLERS_SET, ACE_TRACE, ACE_Fixed_Set< T, ACE_SIZE >::insert(), ACE_Sig_Handlers_Set::instance(), ACE_Fixed_Set_Iterator< T, ACE_SIZE >::next(), ACE_Fixed_Set< T, ACE_SIZE >::remove(), and sigkey_.
00872 { 00873 ACE_TRACE ("ACE_Sig_Handlers::handler"); 00874 ACE_SIG_HANDLERS_SET *handler_set = 00875 ACE_Sig_Handlers_Set::instance (signum); 00876 ACE_SIG_HANDLERS_ITERATOR handler_iterator (*handler_set); 00877 ACE_Event_Handler **eh = 0; 00878 00879 // Find the first handler... 00880 handler_iterator.next (eh); 00881 00882 // ... then remove it from the set ... 00883 handler_set->remove (*eh); 00884 00885 // ... and then insert the new signal handler into the beginning of 00886 // the set (note, this is a bit too tied up in the implementation of 00887 // ACE_Unbounded_Set...). 00888 ACE_Sig_Adapter *temp; 00889 00890 ACE_NEW_RETURN (temp, 00891 ACE_Sig_Adapter (new_sh, 00892 ++ACE_Sig_Handlers::sigkey_), 00893 0); 00894 handler_set->insert (temp); 00895 return *eh; 00896 } |
|
Return the head of the list of ACE_Sig_Handlers associated with SIGNUM. Reimplemented from ACE_Sig_Handler. Definition at line 853 of file Signal.cpp. References ACE_SIG_HANDLERS_ITERATOR, ACE_SIG_HANDLERS_SET, ACE_TRACE, ACE_Sig_Handlers_Set::instance(), and ACE_Fixed_Set_Iterator< T, ACE_SIZE >::next().
00854 { 00855 ACE_TRACE ("ACE_Sig_Handlers::handler"); 00856 ACE_SIG_HANDLERS_SET *handler_set = 00857 ACE_Sig_Handlers_Set::instance (signum); 00858 ACE_SIG_HANDLERS_ITERATOR handler_iterator (*handler_set); 00859 ACE_Event_Handler **eh = 0; 00860 handler_iterator.next (eh); 00861 return *eh; 00862 } |
|
Add a new ACE_Event_Handler and a new sigaction associated with . Passes back the existing ACE_Event_Handler and its sigaction if pointers are non-zero. Returns -1 on failure and a that is >= 0 on success. Reimplemented from ACE_Sig_Handler. Definition at line 623 of file Signal.cpp. References ACE_BIT_DISABLED, ACE_NEW_RETURN, ace_signal_handlers_dispatcher, ACE_SignalHandler, ACE_TRACE, ACE_Sig_Action::flags(), ACE_Sig_Action::handler(), ACE_Sig_Handler::in_range(), ACE_Fixed_Set< T, ACE_SIZE >::insert(), ACE_Sig_Handlers_Set::instance(), ACE_Sig_Action::register_action(), ACE_Fixed_Set< T, ACE_SIZE >::remove(), ACE_Sig_Action::retrieve_action(), SA_RESTART, SA_SIGINFO, SIG_DFL, SIG_IGN, ACE_Sig_Adapter::sigkey(), sigkey_, and third_party_sig_handler_.
00628 { 00629 ACE_TRACE ("ACE_Sig_Handlers::register_handler"); 00630 ACE_MT (ACE_Recursive_Thread_Mutex *lock = 00631 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object 00632 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK); 00633 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock)); 00634 00635 if (ACE_Sig_Handler::in_range (signum)) 00636 { 00637 ACE_Sig_Adapter *ace_sig_adapter = 0; // Our signal handler. 00638 ACE_Sig_Adapter *extern_sh = 0; // An external signal handler. 00639 ACE_Sig_Action sa; 00640 00641 // Get current signal disposition. 00642 sa.retrieve_action (signum); 00643 00644 // Check whether we are already in control of the signal 00645 // handling disposition... 00646 00647 if (!(sa.handler () == ace_signal_handlers_dispatcher 00648 || sa.handler () == ACE_SignalHandler (SIG_IGN) 00649 || sa.handler () == ACE_SignalHandler (SIG_DFL))) 00650 { 00651 // Drat, a 3rd party library has already installed a signal ;-( 00652 00653 // Upto here we never disabled RESTART_MODE. Thus, 00654 // RESTART_MODE can only be changed by 3rd party libraries. 00655 00656 if (ACE_BIT_DISABLED (sa.flags (), SA_RESTART) 00657 && ACE_Sig_Handlers::third_party_sig_handler_) 00658 // Toggling is disallowed since we might break 3rd party 00659 // code. 00660 return -1; 00661 00662 // Note that we've seen a 3rd party handler... 00663 ACE_Sig_Handlers::third_party_sig_handler_ = 1; 00664 00665 // Create a new 3rd party disposition, remembering its 00666 // preferred signal blocking etc...; 00667 ACE_NEW_RETURN (extern_sh, 00668 ACE_Sig_Adapter (sa, 00669 ++ACE_Sig_Handlers::sigkey_), 00670 -1); 00671 // Add the external signal handler to the set of handlers 00672 // for this signal. 00673 if (ACE_Sig_Handlers_Set::instance (signum)->insert (extern_sh) == -1) 00674 { 00675 delete extern_sh; 00676 return -1; 00677 } 00678 } 00679 // Add our new handler at this point. 00680 ACE_NEW_RETURN (ace_sig_adapter, 00681 ACE_Sig_Adapter (new_sh, 00682 ++ACE_Sig_Handlers::sigkey_), 00683 -1); 00684 // Add the ACE signal handler to the set of handlers for this 00685 // signal (make sure it goes before the external one if there is 00686 // one of these). 00687 if (ACE_Sig_Handlers_Set::instance (signum)->insert (ace_sig_adapter) == -1) 00688 { 00689 // We couldn't reinstall our handler, so let's pretend like 00690 // none of this happened... 00691 if (extern_sh) 00692 { 00693 ACE_Sig_Handlers_Set::instance (signum)->remove (extern_sh); 00694 delete extern_sh; 00695 } 00696 delete ace_sig_adapter; 00697 return -1; 00698 } 00699 // If ACE_Sig_Handlers::dispatch() was set we're done. 00700 else if (sa.handler () == ace_signal_handlers_dispatcher) 00701 return ace_sig_adapter->sigkey (); 00702 00703 // Otherwise, we need to register our handler function so that 00704 // all signals will be dispatched through ACE. 00705 else 00706 { 00707 // Make sure that new_disp points to a valid location if the 00708 // user doesn't care... 00709 if (new_disp == 0) 00710 new_disp = &sa; 00711 00712 new_disp->handler (ace_signal_handlers_dispatcher); 00713 00714 // Default is to restart signal handlers. 00715 new_disp->flags (new_disp->flags () | SA_RESTART); 00716 new_disp->flags (new_disp->flags () | SA_SIGINFO); 00717 00718 // Finally install (possibly reinstall) the ACE signal 00719 // handler disposition with the SA_RESTART mode enabled. 00720 if (new_disp->register_action (signum, old_disp) == -1) 00721 { 00722 // Yikes, lots of roll back at this point... 00723 ACE_Sig_Handlers_Set::instance (signum)->remove (ace_sig_adapter); 00724 delete ace_sig_adapter; 00725 00726 if (extern_sh) 00727 { 00728 ACE_Sig_Handlers_Set::instance (signum)->remove (extern_sh); 00729 delete extern_sh; 00730 } 00731 return -1; 00732 } 00733 else // Return the signal key so that programs can cancel this 00734 // handler if they want! 00735 return ace_sig_adapter->sigkey (); 00736 } 00737 } 00738 00739 return -1; 00740 } |
|
Remove an ACE_Event_Handler currently associated with . We remove the handler if (1) its matches the passed as a parameter or (2) if we've been told to remove all the handlers, i.e., == -1. If a new disposition is given it is installed and the previous disposition is returned (if desired by the caller). Returns 0 on success and -1 if is invalid. Reimplemented from ACE_Sig_Handler. Definition at line 748 of file Signal.cpp. References ACE_SIG_HANDLERS_ITERATOR, ACE_SIG_HANDLERS_SET, ACE_TRACE, ACE_Fixed_Set_Iterator_Base< T, ACE_SIZE >::advance(), ACE_Sig_Handler::in_range(), ACE_Sig_Handlers_Set::instance(), ACE_Fixed_Set_Iterator< T, ACE_SIZE >::next(), ACE_Sig_Action::register_action(), ACE_Fixed_Set< T, ACE_SIZE >::remove(), SIG_DFL, ACE_Sig_Adapter::sigkey(), and ACE_Fixed_Set< T, ACE_SIZE >::size().
00752 { 00753 ACE_TRACE ("ACE_Sig_Handlers::remove_handler"); 00754 ACE_MT (ACE_Recursive_Thread_Mutex *lock = 00755 ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object 00756 (ACE_Object_Manager::ACE_SIG_HANDLER_LOCK); 00757 ACE_Guard<ACE_Recursive_Thread_Mutex> m (*lock)); 00758 00759 if (ACE_Sig_Handler::in_range (signum)) 00760 { 00761 ACE_SIG_HANDLERS_SET *handler_set = 00762 ACE_Sig_Handlers_Set::instance (signum); 00763 00764 ACE_SIG_HANDLERS_ITERATOR handler_iterator (*handler_set); 00765 00766 // Iterate through the set of handlers for this signal. 00767 00768 for (ACE_Event_Handler **eh; 00769 handler_iterator.next (eh) != 0; 00770 handler_iterator.advance ()) 00771 { 00772 // Type-safe downcast would be nice here... 00773 ACE_Sig_Adapter *sh = (ACE_Sig_Adapter *) *eh; 00774 00775 // Remove the handler if (1) its key matches the key we've 00776 // been told to remove or (2) if we've been told to remove 00777 // *all* handlers (i.e., <sigkey> == -1). 00778 00779 if (sh->sigkey () == sigkey || sigkey == -1) 00780 { 00781 handler_set->remove (*eh); 00782 delete *eh; 00783 } 00784 } 00785 00786 if (handler_set->size () == 0) 00787 { 00788 // If there are no more handlers left for a signal then 00789 // register the new disposition or restore the default 00790 // disposition. 00791 00792 ACE_Sig_Action sa (SIG_DFL, (sigset_t *) 0); 00793 00794 if (new_disp == 0) 00795 new_disp = &sa; 00796 00797 return new_disp->register_action (signum, old_disp); 00798 } 00799 return 0; 00800 } 00801 else 00802 return -1; 00803 } |
|
Declare the dynamic allocation hooks.
Reimplemented from ACE_Sig_Handler. |
|
Keeps track of the id that uniquely identifies each registered signal handler. This id can be used to cancel a timer via the method. Definition at line 574 of file Signal.cpp. Referenced by handler(), and register_handler(). |
|
If this is > 0 then a 3rd party library has registered a handler... Definition at line 578 of file Signal.cpp. Referenced by register_handler(). |