qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r731739 - in /qpid/trunk/qpid/cpp/src: qpid/broker/Daemon.cpp tests/BrokerFixture.h
Date Mon, 05 Jan 2009 22:01:16 GMT
Author: aconway
Date: Mon Jan  5 14:01:15 2009
New Revision: 731739

URL: http://svn.apache.org/viewvc?rev=731739&view=rev
Log:
Minor logging fixes.

cpp/src/tests/BrokerFixture.h: make tests quiet, log with error+
qpid/broker/Daemon.cpp: print to stderr in parent process if child fails.

Modified:
    qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp
    qpid/trunk/qpid/cpp/src/tests/BrokerFixture.h

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp?rev=731739&r1=731738&r2=731739&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp Mon Jan  5 14:01:15 2009
@@ -108,51 +108,61 @@
 }
 
 uint16_t Daemon::wait(int timeout) {            // parent waits for child.
-    errno = 0;                  
-    struct timeval tv;
-    tv.tv_sec = timeout;
-    tv.tv_usec = 0;
-
-    /*
-     * Rewritten using low-level IO, for compatibility 
-     * with earlier Boost versions, i.e. 103200.
-     */
-    fd_set fds;
-    FD_ZERO(&fds);
-    FD_SET(pipeFds[0], &fds);
-    int n=select(FD_SETSIZE, &fds, 0, 0, &tv);
-    if(n==0) throw Exception("Timed out waiting for daemon");
-    if(n<0) throw ErrnoException("Error waiting for daemon");
-    uint16_t port = 0;
-    /*
-     * Read the child's port number from the pipe.
-     */
-    int desired_read = sizeof(uint16_t);
-    if ( desired_read > ::read(pipeFds[0], & port, desired_read) ) 
-      throw Exception("Cannot read from child process.");
-
-    /*
-     * If the port number is 0, the child has put an error message
-     * on the pipe.  Get it and throw it.
-     */
-     if ( 0 == port ) {
-       // Skip whitespace
-       char c = ' ';
-       while ( isspace(c) ) {
-         if ( 1 > ::read(pipeFds[0], &c, 1) )
-           throw Exception("Child port == 0, and no error message on pipe.");
-       }
-
-       // Get Message
-       string errmsg;
-       do {
-           errmsg += c;
-       } while (::read(pipeFds[0], &c, 1));
-       throw Exception("Daemon startup failed"+
-                       (errmsg.empty() ? string(".") : ": " + errmsg));
-     }
-
-    return port;
+    try {
+        errno = 0;                  
+        struct timeval tv;
+        tv.tv_sec = timeout;
+        tv.tv_usec = 0;
+
+        /*
+         * Rewritten using low-level IO, for compatibility 
+         * with earlier Boost versions, i.e. 103200.
+         */
+        fd_set fds;
+        FD_ZERO(&fds);
+        FD_SET(pipeFds[0], &fds);
+        int n=select(FD_SETSIZE, &fds, 0, 0, &tv);
+        if(n==0) throw Exception("Timed out waiting for daemon");
+        if(n<0) throw ErrnoException("Error waiting for daemon");
+        uint16_t port = 0;
+        /*
+         * Read the child's port number from the pipe.
+         */
+        int desired_read = sizeof(uint16_t);
+        if ( desired_read > ::read(pipeFds[0], & port, desired_read) ) 
+            throw Exception("Cannot read from child process.");
+
+        /*
+         * If the port number is 0, the child has put an error message
+         * on the pipe.  Get it and throw it.
+         */
+        if ( 0 == port ) {
+            // Skip whitespace
+            char c = ' ';
+            while ( isspace(c) ) {
+                if ( 1 > ::read(pipeFds[0], &c, 1) )
+                    throw Exception("Child port == 0, and no error message on pipe.");
+            }
+
+            // Get Message
+            string errmsg;
+            do {
+                errmsg += c;
+            } while (::read(pipeFds[0], &c, 1));
+            throw Exception("Daemon startup failed"+
+                            (errmsg.empty() ? string(".") : ": " + errmsg));
+        }
+        return port;
+    }
+    catch (const std::exception& e) {
+        // Print directly to cerr. The caller will catch and log the
+        // exception, but in the case of a daemon parent process we
+        // also need to be sure the error goes to stderr. A
+        // dameon's logging configuration normally does not log to
+        // stderr. 
+        std::cerr << e.what() << endl;
+        throw;
+    }
 }
 
 

Modified: qpid/trunk/qpid/cpp/src/tests/BrokerFixture.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/BrokerFixture.h?rev=731739&r1=731738&r2=731739&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/BrokerFixture.h (original)
+++ qpid/trunk/qpid/cpp/src/tests/BrokerFixture.h Mon Jan  5 14:01:15 2009
@@ -23,12 +23,15 @@
  */
 
 #include "SocketProxy.h"
-#include "qpid/sys/Thread.h"
+
 #include "qpid/broker/Broker.h"
 #include "qpid/client/Connection.h"
 #include "qpid/client/ConnectionImpl.h"
 #include "qpid/client/Session.h"
 #include "qpid/client/SubscriptionManager.h"
+#include "qpid/log/Logger.h"
+#include "qpid/log/Options.h"
+#include "qpid/sys/Thread.h"
 #include <boost/noncopyable.hpp>
 
 /**
@@ -42,6 +45,13 @@
     qpid::sys::Thread brokerThread;
 
     BrokerFixture(Broker::Options opts=Broker::Options()) {
+        // Keep the tests quiet unless logging env. vars have been set by user.
+        if (!::getenv("QPID_LOG_ENABLE") && !::getenv("QPID_TRACE")) {
+            qpid::log::Options logOpts;
+            logOpts.selectors.clear();
+            logOpts.selectors.push_back("error+");
+            qpid::log::Logger::instance().configure(logOpts);
+        }
         opts.port=0;
         // Management doesn't play well with multiple in-process brokers.
         opts.enableMgmt=false;  



Mime
View raw message