1 #include "orbsvcs/Log_Macros.h"
2 #include "Signal_Handler.h"
3 #include "tao/ORB_Core.h"
4 #include "ace/Reactor.h"
6 TAO_LB_Signal_Handler::TAO_LB_Signal_Handler (CORBA::ORB_ptr orb
,
7 PortableServer::POA_ptr poa
)
11 #endif /* ACE_HAS_THREADS */
13 orb_ (CORBA::ORB::_duplicate (orb
)),
14 poa_ (PortableServer::POA::_duplicate (poa
))
16 // Register signal handlers.
17 this->sigset_
.sig_add (SIGINT
);
18 this->sigset_
.sig_add (SIGTERM
);
22 TAO_LB_Signal_Handler::svc (void)
24 // This method is only invoked when performing synchronous signal
29 // Block waiting for the registered signals.
30 if (ACE_OS::sigwait (this->sigset_
, &signum
) == -1)
32 ORBSVCS_ERROR_RETURN ((LM_ERROR
,
34 "ERROR waiting on signal"),
38 ACE_ASSERT (signum
== SIGINT
|| signum
== SIGTERM
);
40 // ORBSVCS_DEBUG ((LM_DEBUG,
41 // ACE_TEXT ("(%P|%t) synchronous signal handler done\n")));
43 return this->perform_cleanup (signum
);
47 TAO_LB_Signal_Handler::activate (long flags
,
53 ACE_hthread_t thread_handles
[],
56 ACE_thread_t thread_ids
[],
57 const char* thr_name
[])
59 // sigwait() is not implemented on MS Windows. Handle signals
60 // asynchronously through the ORB's reactor in that case instead.
61 // Otherwise, handle signals synchronously in another thread.
63 #if defined (ACE_HAS_THREADS) && !defined (ACE_WIN32)
64 return this->ACE_Task_Base::activate (flags
,
76 ACE_UNUSED_ARG (flags
);
77 ACE_UNUSED_ARG (n_threads
);
78 ACE_UNUSED_ARG (force_active
);
79 ACE_UNUSED_ARG (priority
);
80 ACE_UNUSED_ARG (grp_id
);
81 ACE_UNUSED_ARG (task
);
82 ACE_UNUSED_ARG (thread_handles
);
83 ACE_UNUSED_ARG (stack
);
84 ACE_UNUSED_ARG (stack_size
);
85 ACE_UNUSED_ARG (thread_ids
);
86 ACE_UNUSED_ARG (thr_name
);
89 this->orb_
->orb_core ()->reactor ()->register_handler (this->sigset_
,
91 #endif /* ACE_HAS_THREADS */
95 TAO_LB_Signal_Handler::handle_signal (int signum
, siginfo_t
*, ucontext_t
*)
97 // ORBSVCS_DEBUG ((LM_DEBUG,
98 // ACE_TEXT ("(%P|%t) ASYNCHRONOUS signal handler done\n")));
100 // This method is only used in the asynchronous signal handling case
101 // (i.e. when single-threaded build is used).
103 // @note Is it okay to perform ORB operations from this method? The
104 // issue here is whether or not
105 // ACE_Event_Handler::handle_signal() is called from within an
106 // OS signal handler, and if that did occur is it safe to
107 // perform ORB operations?
108 return this->perform_cleanup (signum
);
112 TAO_LB_Signal_Handler::perform_cleanup (int signum
)
118 // Shutting down the POA will cause servants "owned" by the POA
119 // to be destroyed. Servants will then have the opportunity to
120 // clean up all resources they are responsible for.
121 this->poa_
->destroy (1, 1);
123 // Now shutdown the ORB.
124 this->orb_
->shutdown (1);
126 catch (const CORBA::Exception
& ex
)
128 ex
._tao_print_exception ("Caught exception");
130 ORBSVCS_ERROR_RETURN ((LM_ERROR
,
131 "Problem during cleanup initiated by signal %d.\n",