From 6536407690660e10529c826ab3aa21baaa121ea1 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Sat, 23 Dec 2006 17:20:37 +0000 Subject: - 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 --- cpp/src/qpidd.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'cpp/src') 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 #include #include +#include #include +#include 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; } -- cgit v1.2.1