summaryrefslogtreecommitdiff
path: root/cpp/src/qpidd.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2006-12-23 17:20:37 +0000
committerAlan Conway <aconway@apache.org>2006-12-23 17:20:37 +0000
commit6536407690660e10529c826ab3aa21baaa121ea1 (patch)
treeaacbd4397be2fc04e394d77f83732bd77e5f4b99 /cpp/src/qpidd.cpp
parenta958033ea68c9154da02d4378c4031f9dc02897e (diff)
downloadqpid-python-6536407690660e10529c826ab3aa21baaa121ea1.tar.gz
- rpm: make rpm now builds RPMs under rpm/ directory.
- src/qpidd.cpp: added --daemon option to run as daemon. - etc/qpidd: fixed bugs in init.rc script. - qpidc.spec: fixed rpmlint warnings, added apache URL git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@489905 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpidd.cpp')
-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;
}