Index: munin-node/src/plugins/external/ExternalMuninNodePlugin.cpp =================================================================== --- munin-node/src/plugins/external/ExternalMuninNodePlugin.cpp (revision 11) +++ munin-node/src/plugins/external/ExternalMuninNodePlugin.cpp (working copy) @@ -19,13 +19,37 @@ #include "StdAfx.h" #include "ExternalMuninNodePlugin.h" +#include "../../core/Service.h" + + +void removeAllNL (std::string &str) +{ + std::string temp; + for (unsigned int i = 0; i < str.length(); i++) + if ((str[i] != '\r') && (str[i] != '\n')) temp += str[i]; + str = temp; +} + +void removeAllLF (std::string &str) +{ + std::string temp; + for (unsigned int i = 0; i < str.length(); i++) + if ((str[i] != '\r')) temp += str[i]; + str = temp; +} + + + ExternalMuninNodePlugin::ExternalMuninNodePlugin(const std::string &externalPlugin) : m_ExternalPlugin(externalPlugin) { m_Name = Run("name"); + removeAllNL(m_Name); // Check that the name is valid - if (m_Name.find(" ") != m_Name.npos) - m_Name = ""; + if (m_Name.find(" ") != m_Name.npos) { + _Module.LogError("Failed to load External plugin: %s", m_Name.c_str()); + m_Name = ""; + } } ExternalMuninNodePlugin::~ExternalMuninNodePlugin() @@ -47,7 +71,8 @@ { std::string output = Run(""); if (output.length() > 0) { - strncpy(buffer, output.c_str(), len); + removeAllLF(output); + strncpy(buffer, output.c_str(), len); return 0; } return -1; Index: munin-node/src/core/MuninPluginManager.cpp =================================================================== --- munin-node/src/core/MuninPluginManager.cpp (revision 11) +++ munin-node/src/core/MuninPluginManager.cpp (working copy) @@ -90,7 +90,7 @@ if (plugin->IsLoaded()) { AddPlugin(plugin); } else { - _Module.LogEvent("Failed to load External plugin: %s", filename.c_str()); + _Module.LogError("Failed to load External plugin: %s", filename.c_str()); delete plugin; } } Index: munin-node/src/core/Service.cpp =================================================================== --- munin-node/src/core/Service.cpp (revision 11) +++ munin-node/src/core/Service.cpp (working copy) @@ -334,3 +334,25 @@ printf("\n"); } } + +void CService::LogError(LPCSTR pFormat, ...) +{ + char chMsg[512]; + va_list pArg; + va_start(pArg, pFormat); + _vsnprintf(chMsg, 512, pFormat, pArg); + va_end(pArg); + chMsg[511] = 0; + + if (m_bService) + { + m_EventLog.Write(EVENTLOG_ERROR_TYPE, A2TConvert(chMsg).c_str()); + } + else + { + // As we don't have an event log handle, just write the error to the console. + printf("ERROR:"); + printf(chMsg); + printf("\n"); + } +} Index: munin-node/src/core/Service.h =================================================================== --- munin-node/src/core/Service.h (revision 11) +++ munin-node/src/core/Service.h (working copy) @@ -26,6 +26,7 @@ BOOL Install(); BOOL Uninstall(DWORD dwTimeout = 10000); void LogEvent(LPCSTR pszFormat, ...); + void LogError(LPCSTR pszFormat, ...); void SetServiceStatus(DWORD dwState); void SetQuiet(bool bQuiet) { m_bQuiet = bQuiet; }; void ShowMessage(LPCTSTR szMessage); Index: munin-node/munin-node.rc =================================================================== --- munin-node/munin-node.rc (revision 11) +++ munin-node/munin-node.rc (working copy) @@ -7,7 +7,7 @@ // // Generated from the TEXTINCLUDE 2 resource. // -#include "afxres.h" +#include "windows.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS @@ -34,7 +34,7 @@ 2 TEXTINCLUDE BEGIN - "#include ""afxres.h""\r\n" + "#include ""windows.h""\r\n" "\0" END