[rhmessaging-commits] rhmessaging commits: r4294 - in mgmt/trunk/sesame/cpp: src and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Wed Sep 15 15:57:44 EDT 2010


Author: tedross
Date: 2010-09-15 15:57:43 -0400 (Wed, 15 Sep 2010)
New Revision: 4294

Modified:
   mgmt/trunk/sesame/cpp/configure.ac
   mgmt/trunk/sesame/cpp/src/Makefile.am
   mgmt/trunk/sesame/cpp/src/SysAgent.cpp
Log:
System ID now comes from the Dbus UUID (thanks in part to a patch by Matt Farrellee)
Errors are now logged rather than printed to stderr.


Modified: mgmt/trunk/sesame/cpp/configure.ac
===================================================================
--- mgmt/trunk/sesame/cpp/configure.ac	2010-09-15 17:13:56 UTC (rev 4293)
+++ mgmt/trunk/sesame/cpp/configure.ac	2010-09-15 19:57:43 UTC (rev 4294)
@@ -173,6 +173,8 @@
 AC_CHECK_PROG([do_doxygen], [doxygen], [yes])
 AM_CONDITIONAL([DOXYGEN], [test x$do_doxygen = xyes])
 
+PKG_CHECK_MODULES([DBUS], [dbus-1])
+
 AC_CONFIG_FILES([
   Makefile
   src/Makefile

Modified: mgmt/trunk/sesame/cpp/src/Makefile.am
===================================================================
--- mgmt/trunk/sesame/cpp/src/Makefile.am	2010-09-15 17:13:56 UTC (rev 4293)
+++ mgmt/trunk/sesame/cpp/src/Makefile.am	2010-09-15 19:57:43 UTC (rev 4294)
@@ -2,6 +2,7 @@
 sesame_CXXFLAGS = $(QPID_CXXFLAGS) -Iqmfgen \
 	-DCONF_FILE=\"$(sysconfdir)/sesame/sesame.conf\" \
 	-DLOCSTATE_DIR=\"$(localstatedir)/lib/sesame\" \
+	$(DBUS_CFLAGS) \
 	-I$(QPID_INCLUDE)
 
 include qmfgen/qmfgen.mk
@@ -10,4 +11,4 @@
 nodist_sesame_SOURCES = $(qmfgen_sources)
 sesame_SOURCES = SysAgent.cpp
 
-sesame_LDADD = $(QPID_LIBS)
+sesame_LDADD = $(QPID_LIBS) $(DBUS_LIBS)

Modified: mgmt/trunk/sesame/cpp/src/SysAgent.cpp
===================================================================
--- mgmt/trunk/sesame/cpp/src/SysAgent.cpp	2010-09-15 17:13:56 UTC (rev 4293)
+++ mgmt/trunk/sesame/cpp/src/SysAgent.cpp	2010-09-15 19:57:43 UTC (rev 4294)
@@ -4,12 +4,15 @@
 #include <qpid/sys/Mutex.h>
 #include "qpid/log/Logger.h"
 #include "qpid/log/SinkOptions.h"
+#include "qpid/log/Statement.h"
 #include "qpid/sys/SystemInfo.h"
 #include "qpid/framing/Uuid.h"
 #include "qpid/types/Uuid.h"
 #include "qmf/com/redhat/sesame/Package.h"
 #include "qmf/com/redhat/sesame/Sysimage.h"
 
+#include <dbus/dbus.h> // for dbus_get_local_machine_id
+
 #include <signal.h>
 #include <unistd.h>
 #include <cstdlib>
@@ -25,16 +28,26 @@
 using qpid::sys::Mutex;
 namespace _qmf = qmf::com::redhat::sesame;
 
+static qpid::types::Uuid fixupDbusUuid(const string& in)
+{
+    stringstream properUuid;
+    properUuid << in.substr(0,8) << "-" << in.substr(8,4) << "-" <<
+        in.substr(12,4) << "-" << in.substr(16,4) << "-" <<
+        in.substr(20,12);
+    qpid::types::Uuid uuid;
+    properUuid >> uuid;
+    return uuid;
+}
 
+
 class SysAgent : public Manageable
 {
     ManagementAgent* agent;
     _qmf::Sysimage*  mgmtObject;
-    qpid::framing::Uuid    uuid;
 
 public:
 
-    SysAgent(ManagementAgent* agent, const string& uuidFile);
+    SysAgent(ManagementAgent* agent, const qpid::types::Uuid& uuid);
     ~SysAgent() { mgmtObject->resourceDestroy(); }
 
     ManagementObject* GetManagementObject(void) const
@@ -62,25 +75,9 @@
     void getMem(Mem& mem);
 };
 
-SysAgent::SysAgent(ManagementAgent* _agent, const string& uuidFile) : agent(_agent)
+SysAgent::SysAgent(ManagementAgent* _agent, const qpid::types::Uuid& uuid) : agent(_agent)
 {
-    // obtain or establish the system-id
-    ifstream input(uuidFile.c_str());
-    if (input.good()) {
-        input >> uuid;
-        input.close();
-    }
-
-    if (uuid.isNull()) {
-        uuid.generate();
-        ofstream output(uuidFile.c_str());
-        if (output.good()) {
-            output << uuid << endl;
-            output.close();
-        }
-    }
-
-    mgmtObject = new _qmf::Sysimage(agent, this, qpid::types::Uuid(uuid.c_array()));
+    mgmtObject = new _qmf::Sysimage(agent, this, uuid);
     setSystemId();
     ifstream distro("/etc/redhat-release");
     if (distro.good()) {
@@ -229,7 +226,7 @@
     if (!options["config"].value.empty()) {
         ifstream input(options["config"].value.c_str());
         if (!input.good()) {
-            cerr << "Can't open config file: " << options["config"].value << endl;
+            QPID_LOG(error, "Can't open config file: " << options["config"].value);
             exit(1);
         }
 
@@ -240,7 +237,7 @@
 
             input.getline(line, 512);
             if (input.fail() && !input.eof()) {
-                cerr << "Line too long in config file: " << options["config"].value << endl;
+                QPID_LOG(error, "Line too long in config file: " << options["config"].value);
                 exit(1);
             }
 
@@ -249,7 +246,7 @@
                 while (*cursor != '\0' && *cursor != '=')
                     cursor++;
                 if (*cursor == '\0') {
-                    cerr << "Missing value in config line: " << line << endl;
+                    QPID_LOG(error, "Missing value in config line: " << line);
                     exit(1);
                 }
                 *cursor = '\0';
@@ -257,7 +254,7 @@
 
                 map<string, Option>::iterator iter = options.find(line);
                 if (iter == options.end()) {
-                    cerr << "Config file option '" << line << "' not known" << endl;
+                    QPID_LOG(error, "Config file option '" << line << "' not known");
                     exit(1);
                 }
 
@@ -274,19 +271,19 @@
         if (arg == "--no-config")
             continue;
         if (arg.substr(0, 2) != "--") {
-            cerr << "Invalid argument: " << arg << endl;
+            QPID_LOG(error, "Invalid argument: " << arg);
             usage();
         }
 
         map<string, Option>::iterator iter = options.find(arg.substr(2));
         if (iter == options.end()) {
-            cerr << "Unknown option: " << arg << endl;
+            QPID_LOG(error, "Unknown option: " << arg);
             usage();
         }
 
         i++;
         if (i == argc) {
-            cerr << "No value for option: " << arg << endl;
+            QPID_LOG(error, "No value for option: " << arg);
             usage();
         }
 
@@ -302,7 +299,7 @@
 
     ifstream input(file.c_str());
     if (!input.good()) {
-        cerr << "Can't read password file" << endl;
+        QPID_LOG(error, "Can't read password file");
         exit(1);
     }
 
@@ -371,7 +368,16 @@
     settings.minSsf = ::atoi(options["min-ssf"].value.c_str());
     settings.maxSsf = ::atoi(options["max-ssf"].value.c_str());
 
-    agent->setName("redhat.com", "sesame");
+    char* uuid_hex = dbus_get_local_machine_id();
+    if (!uuid_hex) {
+        QPID_LOG(error, "Failed to acquire UUID from dbus");
+        return 1;
+    }
+
+    qpid::types::Uuid uuid(fixupDbusUuid(uuid_hex));
+    dbus_free(uuid_hex);
+
+    agent->setName("redhat.com", "sesame", uuid.str());
     agent->init(settings, interval, false, options["state-dir"].value + "/agentdata");
 
     ::close(0);
@@ -379,7 +385,7 @@
     ::close(2);
 
     // Allocate core object
-    SysAgent core(agent, options["state-dir"].value + "/uuid");
+    SysAgent core(agent, uuid);
     core.run();
     return 0;
 }
@@ -389,7 +395,7 @@
     try {
         return main_int(argc, argv);
     } catch(std::exception& e) {
-        cout << "Top Level Exception: " << e.what() << endl;
+        QPID_LOG(error, "Top Level Exception: " << e.what());
     }
 }
 



More information about the rhmessaging-commits mailing list