summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/posix/QpiddBroker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qpid/cpp/src/posix/QpiddBroker.cpp')
-rw-r--r--qpid/cpp/src/posix/QpiddBroker.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/qpid/cpp/src/posix/QpiddBroker.cpp b/qpid/cpp/src/posix/QpiddBroker.cpp
index 831b2e0641..9228c2d18d 100644
--- a/qpid/cpp/src/posix/QpiddBroker.cpp
+++ b/qpid/cpp/src/posix/QpiddBroker.cpp
@@ -59,12 +59,14 @@ const std::string TCP = "tcp";
struct DaemonOptions : public qpid::Options {
bool daemon;
bool quit;
+ bool kill;
bool check;
+ std::vector<int> closeFd;
int wait;
std::string piddir;
std::string transport;
- DaemonOptions() : qpid::Options("Daemon options"), daemon(false), quit(false), check(false), wait(600), transport(TCP)
+ DaemonOptions() : qpid::Options("Daemon options"), daemon(false), quit(false), kill(false), check(false), wait(600), transport(TCP)
{
char *home = ::getenv("HOME");
@@ -78,9 +80,11 @@ struct DaemonOptions : public qpid::Options {
("daemon,d", pure_switch(daemon), "Run as a daemon. Logs to syslog by default in this mode.")
("transport", optValue(transport, "TRANSPORT"), "The transport for which to return the port")
("pid-dir", optValue(piddir, "DIR"), "Directory where port-specific PID file is stored")
+ ("close-fd", optValue(closeFd, "FD"), "File descriptors that the daemon should close")
("wait,w", optValue(wait, "SECONDS"), "Sets the maximum wait time to initialize or shutdown the daemon. If the daemon fails to initialize/shutdown, prints an error and returns 1")
("check,c", pure_switch(check), "Prints the daemon's process ID to stdout and returns 0 if the daemon is running, otherwise returns 1")
- ("quit,q", pure_switch(quit), "Tells the daemon to shut down");
+ ("quit,q", pure_switch(quit), "Tells the daemon to shut down with an INT signal")
+ ("kill,k", pure_switch(kill), "Kill the daemon with a KILL signal.");
}
};
@@ -132,12 +136,15 @@ struct QpiddDaemon : public Daemon {
/** Code for parent process */
void parent() {
uint16_t port = wait(options->daemon.wait);
- if (options->parent->broker.port == 0
- ) cout << port << endl;
+ if (options->parent->broker.port == 0)
+ cout << port << endl;
}
/** Code for forked child process */
void child() {
+ // Close extra FDs requested in options.
+ for (size_t i = 0; i < options->daemon.closeFd.size(); ++i)
+ ::close(options->daemon.closeFd[i]);
boost::intrusive_ptr<Broker> brokerPtr(new Broker(options->parent->broker));
ScopedSetBroker ssb(brokerPtr);
brokerPtr->accept();
@@ -157,21 +164,22 @@ int QpiddBroker::execute (QpiddOptions *options) {
if (myOptions == 0)
throw Exception("Internal error obtaining platform options");
- if (myOptions->daemon.check || myOptions->daemon.quit) {
+ if (myOptions->daemon.check || myOptions->daemon.quit || myOptions->daemon.kill) {
pid_t pid;
try {
pid = Daemon::getPid(myOptions->daemon.piddir, options->broker.port);
- } catch (const ErrnoException& e) {
+ } catch (const Exception& e) {
// This is not a critical error, usually means broker is not running
- QPID_LOG(notice, "Cannot stop broker: " << e.what());
+ QPID_LOG(notice, "Broker is not running: " << e.what());
return 1;
}
if (pid < 0)
return 1;
if (myOptions->daemon.check)
cout << pid << endl;
- if (myOptions->daemon.quit) {
- if (kill(pid, SIGINT) < 0)
+ if (myOptions->daemon.quit || myOptions->daemon.kill) {
+ int signal = myOptions->daemon.kill ? SIGKILL : SIGINT;
+ if (kill(pid, signal) < 0)
throw Exception("Failed to stop daemon: " + qpid::sys::strError(errno));
// Wait for the process to die before returning
int retry=myOptions->daemon.wait*1000; // Try up to "--wait N" seconds, do retry every millisecond