summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2010-07-01 18:59:20 +0000
committerAlan Conway <aconway@apache.org>2010-07-01 18:59:20 +0000
commit48f7ecda226f9cfdb53ffb20695403046401f06a (patch)
treed97460eacca9c1916d00004d85088002eb41546c /cpp/src
parentc54cd19d2d5b1e8ab5cc36ca7e1b1068b6ff7be2 (diff)
downloadqpid-python-48f7ecda226f9cfdb53ffb20695403046401f06a.tar.gz
Ensure broker is deleted in main thread, not by global destructors.
Finish the fix of r959661 by making it exception safe. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@959746 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/posix/QpiddBroker.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/cpp/src/posix/QpiddBroker.cpp b/cpp/src/posix/QpiddBroker.cpp
index b340e3e52b..bc45b27a2a 100644
--- a/cpp/src/posix/QpiddBroker.cpp
+++ b/cpp/src/posix/QpiddBroker.cpp
@@ -107,6 +107,17 @@ void QpiddOptions::usage() const {
cout << "Usage: qpidd [OPTIONS]" << endl << endl << *this << endl;
}
+// Set the broker pointer on the signal handler, then reset at end of scope.
+// This is to ensure that the signal handler doesn't keep a broker
+// reference after main() has returned.
+//
+struct ScopedSetBroker {
+ ScopedSetBroker(const boost::intrusive_ptr<Broker>& broker) {
+ qpid::broker::SignalHandler::setBroker(broker);
+ }
+ ~ScopedSetBroker() { qpid::broker::SignalHandler::setBroker(0); }
+};
+
struct QpiddDaemon : public Daemon {
QpiddPosixOptions *options;
@@ -123,12 +134,11 @@ struct QpiddDaemon : public Daemon {
/** Code for forked child process */
void child() {
boost::intrusive_ptr<Broker> brokerPtr(new Broker(options->parent->broker));
- qpid::broker::SignalHandler::setBroker(brokerPtr);
+ ScopedSetBroker ssb(brokerPtr);
brokerPtr->accept();
uint16_t port=brokerPtr->getPort(options->daemon.transport);
ready(port); // Notify parent.
brokerPtr->run();
- broker::SignalHandler::setBroker(0); // Delete broker in this thread.
}
};
@@ -170,12 +180,11 @@ int QpiddBroker::execute (QpiddOptions *options) {
}
else { // Non-daemon broker.
boost::intrusive_ptr<Broker> brokerPtr(new Broker(options->broker));
- broker::SignalHandler::setBroker(brokerPtr);
+ ScopedSetBroker ssb(brokerPtr);
brokerPtr->accept();
if (options->broker.port == 0 || myOptions->daemon.transport != TCP)
cout << uint16_t(brokerPtr->getPort(myOptions->daemon.transport)) << endl;
brokerPtr->run();
- broker::SignalHandler::setBroker(0); // Delete broker in this thread.
}
return 0;
}