summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/qpid/broker/Daemon.cpp18
-rw-r--r--cpp/src/qpid/broker/Daemon.h8
-rw-r--r--cpp/src/qpidd.cpp10
3 files changed, 18 insertions, 18 deletions
diff --git a/cpp/src/qpid/broker/Daemon.cpp b/cpp/src/qpid/broker/Daemon.cpp
index 0c2092021f..7f73f764e7 100644
--- a/cpp/src/qpid/broker/Daemon.cpp
+++ b/cpp/src/qpid/broker/Daemon.cpp
@@ -71,18 +71,14 @@ struct LockFile {
} // namespace
-Daemon::Daemon() {
+Daemon::Daemon(std::string _pidDir) : pidDir(_pidDir) {
pid = -1;
pipeFds[0] = pipeFds[1] = -1;
}
-string Daemon::dir() {
- return (getuid() == 0 ? "/var/run" : "/tmp");
-}
-
-string Daemon::pidFile(uint16_t port) {
+string Daemon::pidFile(string pidDir, uint16_t port) {
ostringstream path;
- path << dir() << "/qpidd." << port << ".pid";
+ path << pidDir << "/qpidd." << port << ".pid";
return path.str();
}
@@ -110,7 +106,7 @@ void Daemon::fork()
// Misc
throwIf(setsid()<0, "Cannot set session ID");
- throwIf(chdir(dir().c_str()) < 0, "Cannot change directory to "+dir());
+ throwIf(chdir(pidDir.c_str()) < 0, "Cannot change directory to "+pidDir);
umask(027);
// Child behavior
@@ -197,7 +193,7 @@ uint16_t Daemon::wait(int timeout) { // parent waits for child.
* hears the good news, it ill exit.
*/
void Daemon::ready(uint16_t port) { // child
- lockFile = pidFile(port);
+ lockFile = pidFile(pidDir, port);
LockFile lf(lockFile, true);
/*
@@ -228,8 +224,8 @@ void Daemon::ready(uint16_t port) { // child
* The parent process reads the child's pid
* from the lockfile.
*/
-pid_t Daemon::getPid(uint16_t port) {
- string name = pidFile(port);
+pid_t Daemon::getPid(string _pidDir, uint16_t port) {
+ string name = pidFile(_pidDir, port);
LockFile lf(name, false);
pid_t pid;
diff --git a/cpp/src/qpid/broker/Daemon.h b/cpp/src/qpid/broker/Daemon.h
index 821334c11e..7d683232b1 100644
--- a/cpp/src/qpid/broker/Daemon.h
+++ b/cpp/src/qpid/broker/Daemon.h
@@ -35,9 +35,9 @@ class Daemon : private boost::noncopyable
{
public:
/** Check daemon is running on port, throw exception if not */
- static pid_t getPid(uint16_t port);
+ static pid_t getPid(std::string pidDir, uint16_t port);
- Daemon();
+ Daemon(std::string pidDir);
virtual ~Daemon();
@@ -68,12 +68,12 @@ class Daemon : private boost::noncopyable
void ready(uint16_t port);
private:
- static std::string dir();
- static std::string pidFile(uint16_t port);
+ static std::string pidFile(std::string pidDir, uint16_t port);
pid_t pid;
int pipeFds[2];
std::string lockFile;
+ std::string pidDir;
};
}} // namespace qpid::broker
diff --git a/cpp/src/qpidd.cpp b/cpp/src/qpidd.cpp
index 338c5d51f7..d5f570b458 100644
--- a/cpp/src/qpidd.cpp
+++ b/cpp/src/qpidd.cpp
@@ -60,11 +60,13 @@ struct DaemonOptions : public qpid::Options {
bool quit;
bool check;
int wait;
+ std::string piddir;
- DaemonOptions() : qpid::Options("Daemon options"), daemon(false), quit(false), check(false), wait(10)
+ DaemonOptions() : qpid::Options("Daemon options"), daemon(false), quit(false), check(false), wait(10), piddir("/tmp")
{
addOptions()
("daemon,d", optValue(daemon), "Run as a daemon.")
+ ("pid-dir", optValue(piddir, "DIR"), "Directory where port-specific PID file is stored")
("wait,w", optValue(wait, "SECONDS"), "Sets the maximum wait time to initialize the daemon. If the daemon fails to initialize, prints an error and returns 1")
("check,c", optValue(check), "Prints the daemon's process ID to stdout and returns 0 if the daemon is running, otherwise returns 1")
("quit,q", optValue(quit), "Tells the daemon to shut down");
@@ -127,6 +129,8 @@ void shutdownHandler(int /*signal*/){
}
struct QpiddDaemon : public Daemon {
+ QpiddDaemon(std::string pidDir) : Daemon(pidDir) {}
+
/** Code for parent process */
void parent() {
uint16_t port = wait(options->daemon.wait);
@@ -216,7 +220,7 @@ int main(int argc, char* argv[])
// Options that affect a running daemon.
if (options->daemon.check || options->daemon.quit) {
- pid_t pid = Daemon::getPid(options->broker.port);
+ pid_t pid = Daemon::getPid(options->daemon.piddir, options->broker.port);
if (pid < 0)
return 1;
if (options->daemon.check)
@@ -240,7 +244,7 @@ int main(int argc, char* argv[])
if (options->daemon.daemon) {
// Fork the daemon
- QpiddDaemon d;
+ QpiddDaemon d(options->daemon.piddir);
d.fork();
}
else { // Non-daemon broker.