[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH 19/20] Dynamically allocate the buffer for logging



Allows log messages longer than 255 characters

Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 src/liteagent/LiteAgent.cpp   | 21 +++++++++++++++++++--
 src/liteagent/XenIfaceItf.cpp | 12 +++++++++++-
 src/liteagent/XenIfaceItf.h   |  3 +++
 3 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/liteagent/LiteAgent.cpp b/src/liteagent/LiteAgent.cpp
index 568a2cb..8599d52 100644
--- a/src/liteagent/LiteAgent.cpp
+++ b/src/liteagent/LiteAgent.cpp
@@ -79,14 +79,31 @@ static CLiteAgent s_service;
 
 /*static*/ void CLiteAgent::Log(const char* fmt, ...)
 {
-    char message[256];
+    char* message;
+    size_t length;
     va_list args;
 
     va_start(args, fmt);
-    vsnprintf_s(message, sizeof(message), sizeof(message)/sizeof(message[0]) - 
1, fmt, args);
+    length = _vscprintf(fmt, args);
     va_end(args);
 
+    message = new char[length + 1];
+    if (message == NULL)
+        return;
+
+    va_start(args, fmt);
+    vsnprintf_s(message, (length + 1) * sizeof(char), length, fmt, args);
+    va_end(args);
+
+    message[length] = 0;
     OutputDebugString(message);
+
+    CCritSec crit(&s_service.m_crit);
+    if (s_service.m_dev) {
+        s_service.m_dev->Log(message);
+    }
+
+    delete [] message;
 }
 
 /*static*/ int CLiteAgent::ServiceInstall()
diff --git a/src/liteagent/XenIfaceItf.cpp b/src/liteagent/XenIfaceItf.cpp
index 7e5fadf..2027766 100644
--- a/src/liteagent/XenIfaceItf.cpp
+++ b/src/liteagent/XenIfaceItf.cpp
@@ -142,4 +142,14 @@ bool CXenIfaceItf::SharedInfoGetTime(FILETIME* time)
     return Ioctl(IOCTL_XENIFACE_SHAREDINFO_GET_TIME,
                  NULL, 0,
                  time, sizeof(FILETIME));
-}
\ No newline at end of file
+}
+
+// misc
+bool CXenIfaceItf::Log(const std::string& msg)
+{
+    return Ioctl(IOCTL_XENIFACE_LOG,
+                 (void*)msg.c_str(), (DWORD)msg.length() + 1,
+                 NULL, 0);
+}
+
+
diff --git a/src/liteagent/XenIfaceItf.h b/src/liteagent/XenIfaceItf.h
index e36f189..0ef42a8 100644
--- a/src/liteagent/XenIfaceItf.h
+++ b/src/liteagent/XenIfaceItf.h
@@ -55,6 +55,9 @@ public: // suspend interface
 
 public: // sharedinfo interface
     bool SharedInfoGetTime(FILETIME* time);
+
+public: // misc
+    bool Log(const std::string& msg);
 };
 
 #endif
-- 
1.9.4.msysgit.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.