diff options
| author | Alan Conway <aconway@apache.org> | 2007-06-11 16:05:06 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2007-06-11 16:05:06 +0000 |
| commit | b59a0092f12a07f925bc0b1c7f8cf4949dd374e7 (patch) | |
| tree | c6c188962552bac59bb96b8b7b00d791ae9e4be1 /cpp/src/qpid/broker/Daemon.h | |
| parent | 4c88e1be1c96cf27b8418df2a60c3cbbefd92fcc (diff) | |
| download | qpid-python-b59a0092f12a07f925bc0b1c7f8cf4949dd374e7.tar.gz | |
QPID-504: Print bound port if --port 0 is specified. Not yet used by tests.
* qpidd.cpp:
- With --port 0 print the bound port number to stdout.
- Removed --ppid, --check now prints pid.
* Daemon.cpp/h: Move pid-file generation to caller (qpidd.cpp)
* Exception.cpp: Log a debug message in exception constructors.
Helps to show what exceptions were thrown even if they aren't
logged at a higher level.
* daemon_test: Test new daemon options.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@546180 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/broker/Daemon.h')
| -rw-r--r-- | cpp/src/qpid/broker/Daemon.h | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/cpp/src/qpid/broker/Daemon.h b/cpp/src/qpid/broker/Daemon.h index cf9bf13764..cf7ad37b3a 100644 --- a/cpp/src/qpid/broker/Daemon.h +++ b/cpp/src/qpid/broker/Daemon.h @@ -21,6 +21,7 @@ #include <string> #include <boost/scoped_ptr.hpp> +#include <boost/function.hpp> namespace qpid { namespace broker { @@ -32,24 +33,39 @@ namespace broker { class Daemon { public: - - /** Extract the daemon's name from argv[0] */ - static std::string nameFromArgv0(const char* argv0); + /** Utility function to create pid file name in a standard place + * (may require root acces) using identifier as the file name. + */ + static std::string defaultPidFile(const std::string& identifier); /** - * Creating a Daemon instance forks a daemon process. - *@param name used to create pid files etc. - *@param timeout in seconds for all operations that wait. + * Daemon control object. + *@param pidFileFn Function that will comupte a PID file name. + * Called when pid file is created in ready() + *@param timeout in seconds for any operations that wait. */ - Daemon(const std::string& name, int timeout); + Daemon(boost::function<std::string()> pidFileFn, int timeout); ~Daemon(); - - /** Fork the daemon, wait till it signals readiness */ - pid_t fork(); - /** Child only, send ready signal so parent fork() will return. */ - void ready(); + typedef boost::function<void(Daemon&)> Function; + + /** Fork the daemon. + *@param parent called in the parent process. + *@param child called in the child process. + */ + pid_t fork(Function parent, Function child); + + /** Parent only: wait for child to indicate it is ready. + * @return value child passed to ready() */ + int wait(); + + /** Child only. Notify the parent we are ready and write the + * PID file. + *@param value returned by parent call to wait(). -1 is reserved + * for signalling an error. + */ + void ready(int value); /** Child only, send failed signal so parent fork() will throw. */ void failed(); @@ -67,18 +83,16 @@ class Daemon bool isChild() { return pid == 0; } - std::string getName() const { return name; } - pid_t getPid() const {return pid; } private: class Retval; + static boost::function<std::string()> pidFileFn; + static const char* realPidFileFn(); void notify(int); - static std::string name; - static std::string pidFile; - static const char* getPidFile(); + static std::string identifier; boost::scoped_ptr<Retval> retval; pid_t pid; int timeout; @@ -86,6 +100,4 @@ class Daemon }} // namespace qpid::broker - - #endif /*!_broker_Daemon_h*/ |
