summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpidd.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/cpp/src/qpidd.cpp b/cpp/src/qpidd.cpp
index 8285f1aefb..9f658ebf74 100644
--- a/cpp/src/qpidd.cpp
+++ b/cpp/src/qpidd.cpp
@@ -23,7 +23,9 @@
#include <signal.h>
#include <iostream>
#include <memory>
+#include <cerrno>
#include <config.h>
+#include <unistd.h>
static char const* programName = "qpidd";
@@ -42,6 +44,7 @@ int main(int argc, char** argv)
Configuration config;
try {
config.parse(programName, argc, argv);
+
if(config.isHelp()){
config.usage();
}else if(config.isVersion()){
@@ -50,9 +53,26 @@ int main(int argc, char** argv)
}else{
broker = Broker::create(config);
signal(SIGINT, handle_signal);
+ if (config.isDaemon()) {
+ // Detach & run as daemon.
+ int chdirRoot = 0; // 0 means chdir to root.
+ int closeStd = 0; // 0 means close stdin/out/err
+ if (daemon(chdirRoot, closeStd) < 0) {
+ char buf[512];
+
+ std::cerr << "Failed to detach as daemon: "
+ << strerror_r(errno, buf, sizeof(buf))
+ << std::endl;;
+ return 1;
+ }
+ }
broker->run();
}
return 0;
+ }
+ catch (const Configuration::BadOptionException& e) {
+ std::cerr << e.what() << std::endl << std::endl;
+ config.usage();
} catch(const std::exception& e) {
std::cerr << e.what() << std::endl;
}