diff options
author | Alan Conway <aconway@apache.org> | 2007-08-24 21:04:14 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2007-08-24 21:04:14 +0000 |
commit | 69237a07946e9cf442a9bd86e97956cc7f17a33e (patch) | |
tree | 2bcfe5baeb7eb1091e608611f08197e4dc343005 /cpp/src | |
parent | fa15956ebff52da55526b7a9f0cce0f7b904fcbf (diff) | |
download | qpid-python-69237a07946e9cf442a9bd86e97956cc7f17a33e.tar.gz |
* src/qpid/broker/Daemon.cpp: Additional logging.
* configure.ac: Fixed problem with openais check.
* src/tests/test_env: Remove LD_PRELOAD dlclose_noop, only for CppUnit.
* src/tests/run-unit-tests: Added LD_PRELOAD dlclose_noop.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@569520 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/broker/Daemon.cpp | 63 | ||||
-rwxr-xr-x | cpp/src/tests/run-unit-tests | 4 | ||||
-rwxr-xr-x | cpp/src/tests/test_env | 4 |
3 files changed, 42 insertions, 29 deletions
diff --git a/cpp/src/qpid/broker/Daemon.cpp b/cpp/src/qpid/broker/Daemon.cpp index 27ac72a1e2..0bb3449289 100644 --- a/cpp/src/qpid/broker/Daemon.cpp +++ b/cpp/src/qpid/broker/Daemon.cpp @@ -39,8 +39,8 @@ namespace { /** Throw an exception containing msg and strerror if throwIf is true. * Name is supposed to be reminiscent of perror(). */ -void terror(bool throwIf, const string& msg, int errNo=errno) { - if (throwIf) +void throwIf(bool condition, const string& msg, int errNo=errno) { + if (condition) throw Exception(msg + (errNo? ": "+strError(errNo) : string("."))); } @@ -53,8 +53,8 @@ struct LockFile : public fdstream { errno = 0; int flags=create ? O_WRONLY|O_CREAT|O_NOFOLLOW : O_RDWR; fd = ::open(path.c_str(), flags, 0644); - terror(fd < 0,"Cannot open "+path); - terror(::lockf(fd, F_TLOCK, 0) < 0, "Cannot lock "+path); + throwIf(fd < 0,"Cannot open "+path); + throwIf(::lockf(fd, F_TLOCK, 0) < 0, "Cannot lock "+path); open(boost::iostreams::file_descriptor(fd)); } @@ -89,23 +89,25 @@ string Daemon::pidFile(uint16_t port) { void Daemon::fork() { - terror(pipe(pipeFds) < 0, "Can't create pipe"); - terror((pid = ::fork()) < 0, "Daemon fork failed"); + throwIf(pipe(pipeFds) < 0, "Can't create pipe"); + throwIf((pid = ::fork()) < 0, "Daemon fork failed"); if (pid == 0) { // Child try { + QPID_LOG(debug, "Forked daemon child process"); + // File descriptors - terror(::close(pipeFds[0])<0, "Cannot close read pipe"); - terror(::close(0)<0, "Cannot close stdin"); - terror(::close(1)<0, "Cannot close stdout"); - terror(::close(2)<0, "Cannot close stderr"); + throwIf(::close(pipeFds[0])<0, "Cannot close read pipe"); + throwIf(::close(0)<0, "Cannot close stdin"); + throwIf(::close(1)<0, "Cannot close stdout"); + throwIf(::close(2)<0, "Cannot close stderr"); int fd=::open("/dev/null",O_RDWR); // stdin - terror(fd != 0, "Cannot re-open stdin"); - terror(::dup(fd)<0, "Cannot re-open stdout"); - terror(::dup(fd)<0, "Cannot re-open stderror"); + throwIf(fd != 0, "Cannot re-open stdin"); + throwIf(::dup(fd)<0, "Cannot re-open stdout"); + throwIf(::dup(fd)<0, "Cannot re-open stderror"); // Misc - terror(setsid()<0, "Cannot set session ID"); - terror(chdir(dir().c_str()) < 0, "Cannot change directory to "+dir()); + throwIf(setsid()<0, "Cannot set session ID"); + throwIf(chdir(dir().c_str()) < 0, "Cannot change directory to "+dir()); umask(027); // Child behavior @@ -138,17 +140,26 @@ uint16_t Daemon::wait(int timeout) { // parent waits for child. fd_set fds; FD_ZERO(&fds); FD_SET(pipeFds[0], &fds); - terror(1 != select(FD_SETSIZE, &fds, 0, 0, &tv), "No response from daemon process"); - + int n=select(FD_SETSIZE, &fds, 0, 0, &tv); + throwIf(n==0, "Timed out waiting for daemon"); + throwIf(n<0, "Error waiting for daemon"); fdstream pipe(pipeFds[0]); - uint16_t value = 0; - pipe >> value >> skipws; - if (value == 0) { - string errmsg; - getline(pipe, errmsg); - throw Exception("Daemon startup failed"+ (errmsg.empty() ? string(".") : ": " + errmsg)); + pipe.exceptions(ios::failbit|ios::badbit|ios::eofbit); + uint16_t port = 0; + try { + pipe >> port; + if (port == 0) { + string errmsg; + pipe >> skipws; + getline(pipe, errmsg); + throw Exception("Daemon startup failed"+ + (errmsg.empty() ? string(".") : ": " + errmsg)); + } + } + catch (const fdstream::failure& e) { + throw Exception(string("Failed to read daemon port: ")+e.what()); } - return value; + return port; } void Daemon::ready(uint16_t port) { // child @@ -158,7 +169,9 @@ void Daemon::ready(uint16_t port) { // child if (lf.fail()) throw Exception("Cannot write lock file "+lockFile); fdstream pipe(pipeFds[1]); - pipe << port << endl;; + QPID_LOG(debug, "Daemon ready on port: " << port); + pipe << port << endl; + throwIf(!pipe.good(), "Error writing to parent"); } pid_t Daemon::getPid(uint16_t port) { diff --git a/cpp/src/tests/run-unit-tests b/cpp/src/tests/run-unit-tests index a3113b14ee..ce8f488b29 100755 --- a/cpp/src/tests/run-unit-tests +++ b/cpp/src/tests/run-unit-tests @@ -22,5 +22,7 @@ done test -z "$TEST_ARGS" && TEST_ARGS=".libs/*Test.so" test -z "$srcdir" && srcdir=. -exec $srcdir/test_env DllPlugInTester -c -b $TEST_ARGS + +# libdlclose_noop prevents unloading symbols needed for valgrind output. +LD_PRELOAD=.libs/libdlclose_noop.so exec $srcdir/test_env DllPlugInTester -c -b $TEST_ARGS diff --git a/cpp/src/tests/test_env b/cpp/src/tests/test_env index c73cac43ea..3fdfaa8a88 100755 --- a/cpp/src/tests/test_env +++ b/cpp/src/tests/test_env @@ -34,10 +34,8 @@ vg_check() true } -# libdlclose_noop prevents unloading symbols needed for valgrind output. -preload=.libs/libdlclose_noop.so # Output to file, only display if there is an error. opts=--log-file-exactly=$vg_log -LD_PRELOAD=$preload libtool --mode=execute $VALGRIND $opts -- "$@" || fail=1 +libtool --mode=execute $VALGRIND $opts -- "$@" || fail=1 vg_check && test -z "$fail" |