Author: aconway
Date: Fri Aug 24 14:04:14 2007
New Revision: 569520

URL: http://svn.apache.org/viewvc?rev=569520&view=rev
Log:

        * 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.

Modified:
    incubator/qpid/trunk/qpid/cpp/configure.ac
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/run-unit-tests
    incubator/qpid/trunk/qpid/cpp/src/tests/test_env

Modified: incubator/qpid/trunk/qpid/cpp/configure.ac
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/configure.ac?rev=569520&r1=569519&r2=569520&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/configure.ac (original)
+++ incubator/qpid/trunk/qpid/cpp/configure.ac Fri Aug 24 14:04:14 2007
@@ -140,7 +140,7 @@
 # Check for cluster requirements. Need openais 0.80.3 or higher.x1
 save_ldflags=$LDFLAGS  
 LDFLAGS="$LDFLAGS -L/usr/lib/openais -L/usr/lib64/openais"
-AC_CHECK_LIB([cpg],[cpg_local_get],[cpg_lib=yes])
+AC_CHECK_LIB([cpg],[cpg_local_get],[cpg_lib=yes],[cpg_lib=no])
 AC_CHECK_HEADER([openais/cpg.h],[cpg_h=yes])
 test x$cpg_lib = xyes -a x$cpg_h = xyes && enable_CLUSTER=yes 
 

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp?rev=569520&r1=569519&r2=569520&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp Fri Aug 24 
14:04:14 2007
@@ -39,8 +39,8 @@
 /** 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 @@
         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 @@
 
 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 @@
     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 @@
     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) {

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/run-unit-tests
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/run-unit-tests?rev=569520&r1=569519&r2=569520&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/run-unit-tests (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/run-unit-tests Fri Aug 24 14:04:14 
2007
@@ -22,5 +22,7 @@
 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
 

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/test_env
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/test_env?rev=569520&r1=569519&r2=569520&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/test_env (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/test_env Fri Aug 24 14:04:14 2007
@@ -34,10 +34,8 @@
     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"


Reply via email to