diff options
author | Alan Conway <aconway@apache.org> | 2008-02-07 21:31:21 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-02-07 21:31:21 +0000 |
commit | 910fa22beb64c0c4d64221d9485830035c1663ff (patch) | |
tree | 77fcbee2777dab502d2e093eaa1e467a363557a0 /cpp/src | |
parent | cbd253b15b5ff540c2766cb52e67e28b58b57364 (diff) | |
download | qpid-python-910fa22beb64c0c4d64221d9485830035c1663ff.tar.gz |
Clean shutdown of broker: Moved signal unsafe code from Broker::shutdown
to ~Broker, moved shutdown logging from shutdown handler to main() in qpidd.cpp
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@619646 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/broker/Broker.cpp | 5 | ||||
-rw-r--r-- | cpp/src/qpid/sys/Acceptor.h | 2 | ||||
-rw-r--r-- | cpp/src/qpid/sys/AsynchIOAcceptor.cpp | 2 | ||||
-rw-r--r-- | cpp/src/qpid/sys/Poller.h | 1 | ||||
-rw-r--r-- | cpp/src/qpid/sys/epoll/EpollPoller.cpp | 3 | ||||
-rw-r--r-- | cpp/src/qpidd.cpp | 20 |
6 files changed, 17 insertions, 16 deletions
diff --git a/cpp/src/qpid/broker/Broker.cpp b/cpp/src/qpid/broker/Broker.cpp index 57ff7a550c..1d55db0c0f 100644 --- a/cpp/src/qpid/broker/Broker.cpp +++ b/cpp/src/qpid/broker/Broker.cpp @@ -212,13 +212,16 @@ void Broker::run() { } void Broker::shutdown() { + // NB: this function must be async-signal safe, it must not + // call any function that is not async-signal safe. + // Any unsafe shutdown actions should be done in the destructor. if (acceptor) acceptor->shutdown(); - ManagementAgent::shutdown (); } Broker::~Broker() { shutdown(); + ManagementAgent::shutdown (); delete store; } diff --git a/cpp/src/qpid/sys/Acceptor.h b/cpp/src/qpid/sys/Acceptor.h index 1e87b76e04..7ff03e0eeb 100644 --- a/cpp/src/qpid/sys/Acceptor.h +++ b/cpp/src/qpid/sys/Acceptor.h @@ -39,6 +39,8 @@ class Acceptor : public qpid::SharedObject<Acceptor> virtual std::string getHost() const = 0; virtual void run(ConnectionInputHandlerFactory* factory) = 0; virtual void connect(const std::string& host, int16_t port, ConnectionInputHandlerFactory* factory) = 0; + + /** Note: this function is async-signal safe */ virtual void shutdown() = 0; }; diff --git a/cpp/src/qpid/sys/AsynchIOAcceptor.cpp b/cpp/src/qpid/sys/AsynchIOAcceptor.cpp index 650bb31a68..65d805e492 100644 --- a/cpp/src/qpid/sys/AsynchIOAcceptor.cpp +++ b/cpp/src/qpid/sys/AsynchIOAcceptor.cpp @@ -214,6 +214,8 @@ void AsynchIOAcceptor::connect(const std::string& host, int16_t port, Connection void AsynchIOAcceptor::shutdown() { + // NB: this function must be async-signal safe, it must not + // call any function that is not async-signal safe. poller->shutdown(); } diff --git a/cpp/src/qpid/sys/Poller.h b/cpp/src/qpid/sys/Poller.h index a7a12fdbe8..0d6b4f9308 100644 --- a/cpp/src/qpid/sys/Poller.h +++ b/cpp/src/qpid/sys/Poller.h @@ -96,6 +96,7 @@ public: Poller(); ~Poller(); + /** Note: this function is async-signal safe */ void shutdown(); void addFd(PollerHandle& handle, Direction dir); diff --git a/cpp/src/qpid/sys/epoll/EpollPoller.cpp b/cpp/src/qpid/sys/epoll/EpollPoller.cpp index 3f161ccbbe..67783fc8c8 100644 --- a/cpp/src/qpid/sys/epoll/EpollPoller.cpp +++ b/cpp/src/qpid/sys/epoll/EpollPoller.cpp @@ -253,6 +253,9 @@ void Poller::rearmFd(PollerHandle& handle) { } void Poller::shutdown() { + // NB: this function must be async-signal safe, it must not + // call any function that is not async-signal safe. + // Allow sloppy code to shut us down more than once if (impl->isShutdown) return; diff --git a/cpp/src/qpidd.cpp b/cpp/src/qpidd.cpp index 2a5862a4b9..6c20ebc58f 100644 --- a/cpp/src/qpidd.cpp +++ b/cpp/src/qpidd.cpp @@ -121,20 +121,9 @@ shared_ptr<Broker> brokerPtr; auto_ptr<QpiddOptions> options; void shutdownHandler(int /*signal*/){ - // FIXME aconway 2008-02-07: - // https://bugzilla.redhat.com/show_bug.cgi?id=431928 - - // The following commented code is in no - // way async-signal safe and is causing sporadic hangs on - // shutdown. This handler should push a shutdown event into the - // epoll poller (making sure to use only async-safe functions!) - // and let a poller thread actually do the shutdown. - - // QPID_LOG(notice, "Shutting down on signal " << signal); - // brokerPtr->shutdown(); - - // For now we just die on the signal, no cleanup. - exit(0); + // Note: do not call any async-signal unsafe functions here. + // Do any extra shtudown actions in main() after broker->run() + brokerPtr->shutdown(); } struct QpiddDaemon : public Daemon { @@ -257,7 +246,8 @@ int main(int argc, char* argv[]) brokerPtr.reset(new Broker(options->broker)); if (options->broker.port == 0) cout << uint16_t(brokerPtr->getPort()) << endl; - brokerPtr->run(); + brokerPtr->run(); + QPID_LOG(notice, "Shutting down."); } return 0; } |