Merge branch 'issue-510' into develop
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 21 Feb 2014 22:39:35 +0000 (00:39 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 21 Feb 2014 22:39:35 +0000 (00:39 +0200)
src/agent/core/nxagentd.cpp
src/agent/core/nxagentd.h
src/server/core/main.cpp
src/server/core/netinfo.cpp
src/server/netxmsd/netxmsd.cpp

index 34ae25d..8405cdd 100644 (file)
@@ -539,7 +539,7 @@ static void LoadPlatformSubagent()
          un.sysname[i] = tolower(un.sysname[i]);
       if (!strcmp(un.sysname, "hp-ux"))
          strcpy(un.sysname, "hpux");
-      _sntprintf(szName, MAX_PATH, PKGLIBDIR _T("/%hs.nsm"), un.sysname);
+      _sntprintf(szName, MAX_PATH, _T("%hs.nsm"), un.sysname);
       LoadSubAgent(szName);
    }
 #endif
@@ -635,6 +635,21 @@ BOOL Initialize()
    if (g_debugLevel == (UINT32)NXCONFIG_UNINITIALIZED_VALUE)
       g_debugLevel = 0;
 
+#ifndef _WIN32
+   if (!_tcscmp(g_szDataDirectory, _T("{default}")))
+   {
+      const TCHAR *homeDir = _tgetenv(_T("NETXMS_HOME"));
+      if (homeDir != NULL)
+      {
+         _sntprintf(g_szDataDirectory, MAX_PATH, _T("%s/var/netxms"), homeDir);
+      }
+      else
+      {
+         nx_strncpy(g_szDataDirectory, PREFIX _T("/var/netxms"), MAX_PATH);
+      }
+   }
+#endif
+
    // Open log file
        if (!(g_dwFlags & AF_USE_SYSLOG))
        {
@@ -664,6 +679,8 @@ BOOL Initialize()
                DebugPrintf(INVALID_INDEX, 1, _T("Switched to external subagent loader mode, master agent address is %s"), g_masterAgent);
        }
 
+   DebugPrintf(INVALID_INDEX, 1, _T("Data directory: %s"), g_szDataDirectory);
+
        // Initialize persistent storage
        s_registry = new Config;
        s_registry->setTopLevelTag(_T("registry"));
@@ -1350,7 +1367,17 @@ int main(int argc, char *argv[])
 #if !defined(_WIN32)
        if (!_tcscmp(g_szConfigFile, _T("{search}")))
        {
-               if (_taccess(PREFIX _T("/etc/nxagentd.conf"), 4) == 0)
+      TCHAR path[MAX_PATH] = _T("");
+      const TCHAR *homeDir = _tgetenv(_T("NETXMS_HOME"));
+      if (homeDir != NULL)
+      {
+         _sntprintf(path, MAX_PATH, _T("%s/etc/nxagentd.conf"), homeDir);
+      }
+               if ((path[0] != 0) && (_taccess(path, 4) == 0))
+               {
+                       _tcscpy(g_szConfigFile, path);
+               }
+               else if (_taccess(PREFIX _T("/etc/nxagentd.conf"), 4) == 0)
                {
                        _tcscpy(g_szConfigFile, PREFIX _T("/etc/nxagentd.conf"));
                }
@@ -1369,7 +1396,17 @@ int main(int argc, char *argv[])
        }
        if (!_tcscmp(g_szConfigIncludeDir, _T("{search}")))
        {
-               if (_taccess(PREFIX _T("/etc/nxagentd.conf.d"), 4) == 0)
+      TCHAR path[MAX_PATH] = _T("");
+      const TCHAR *homeDir = _tgetenv(_T("NETXMS_HOME"));
+      if (homeDir != NULL)
+      {
+         _sntprintf(path, MAX_PATH, _T("%s/etc/nxagentd.conf.d"), homeDir);
+      }
+               if ((path[0] != 0) && (_taccess(path, 4) == 0))
+               {
+                       _tcscpy(g_szConfigIncludeDir, path);
+               }
+               else if (_taccess(PREFIX _T("/etc/nxagentd.conf.d"), 4) == 0)
                {
                        _tcscpy(g_szConfigIncludeDir, PREFIX _T("/etc/nxagentd.conf.d"));
                }
@@ -1495,13 +1532,15 @@ int main(int argc, char *argv[])
                                        }
 #else    /* _WIN32 */
                                        if (g_dwFlags & AF_DAEMON)
+               {
                                                if (daemon(0, 0) == -1)
                                                {
                                                        perror("Unable to setup itself as a daemon");
                                                        iExitCode = 4;
                                                }
+               }
                                        if (iExitCode == 0)
-            {
+               {
                                                m_pid = getpid();
                                                if (Initialize())
                                                {
index a5bbe78..75f1453 100644 (file)
@@ -90,7 +90,7 @@
 #define AGENT_DEFAULT_CONFIG_D   _T("{search}")
 #define AGENT_DEFAULT_LOG        _T("/var/log/nxagentd")
 #define AGENT_DEFAULT_FILE_STORE _T("/tmp")
-#define AGENT_DEFAULT_DATA_DIR   PREFIX _T("/var/netxms")
+#define AGENT_DEFAULT_DATA_DIR   _T("{default}")
 #endif
 
 #define REGISTRY_FILE_NAME       _T("registry.dat")
index a3c667b..96945a7 100644 (file)
@@ -335,20 +335,30 @@ static void LoadGlobalConfig()
                g_dwFlags |= AF_CHECK_TRUSTED_NODES;
        if (ConfigReadInt(_T("EnableNXSLContainerFunctions"), 1))
                g_dwFlags |= AF_ENABLE_NXSL_CONTAINER_FUNCS;
-       if (ConfigReadInt(_T("UseFQDNForNodeNames"), 1))
-               g_dwFlags |= AF_USE_FQDN_FOR_NODE_NAMES;
-       if (ConfigReadInt(_T("ApplyDCIFromTemplateToDisabledDCI"), 0))
-               g_dwFlags |= AF_APPLY_TO_DISABLED_DCI_FROM_TEMPLATE;
+   if (ConfigReadInt(_T("UseFQDNForNodeNames"), 1))
+      g_dwFlags |= AF_USE_FQDN_FOR_NODE_NAMES;
+   if (ConfigReadInt(_T("ApplyDCIFromTemplateToDisabledDCI"), 0))
+      g_dwFlags |= AF_APPLY_TO_DISABLED_DCI_FROM_TEMPLATE;
 
-       if (g_szDataDir[0] == 0)
-       {
-               ConfigReadStr(_T("DataDirectory"), g_szDataDir, MAX_PATH, DEFAULT_DATA_DIR);
-               DbgPrintf(1, _T("Data directory set to %s from server configuration variable"), g_szDataDir);
-       }
-       else
-       {
-               DbgPrintf(1, _T("Using data directory %s"), g_szDataDir);
-       }
+   if (g_szDataDir[0] == 0)
+   {
+      const TCHAR *homeDir = _tgetenv(_T("NETXMS_HOME"));
+      if (homeDir != NULL)
+      {
+         TCHAR path[MAX_PATH];
+         _sntprintf(path, MAX_PATH, _T("%s/share/netxms"), homeDir);
+         ConfigReadStr(_T("DataDirectory"), g_szDataDir, MAX_PATH, path);
+      }
+      else
+      {
+         ConfigReadStr(_T("DataDirectory"), g_szDataDir, MAX_PATH, DEFAULT_DATA_DIR);
+      }
+      DbgPrintf(1, _T("Data directory set to %s from server configuration variable"), g_szDataDir);
+   }
+   else
+   {
+      DbgPrintf(1, _T("Using data directory %s"), g_szDataDir);
+   }
 
    g_icmpPingTimeout = ConfigReadInt(_T("IcmpPingTimeout"), 1500);
        g_icmpPingSize = ConfigReadInt(_T("IcmpPingSize"), 46);
index e0821b6..73d2280 100644 (file)
@@ -76,7 +76,15 @@ void InitLocalNetInfo()
          un.sysname[i] = tolower(un.sysname[i]);
       if (!strcmp(un.sysname, "hp-ux"))
          strcpy(un.sysname, "hpux");
-      _sntprintf(szName, MAX_PATH, PKGLIBDIR _T("/%hs.nsm"), un.sysname);
+      const TCHAR *homeDir = _tgetenv(_T("NETXMS_HOME"));
+      if (homeDir != NULL)
+      {
+         _sntprintf(szName, MAX_PATH, _T("%s/lib/netxms/%hs.nsm"), homeDir, un.sysname);
+      }
+      else
+      {
+         _sntprintf(szName, MAX_PATH, PKGLIBDIR _T("/%hs.nsm"), un.sysname);
+      }
 
       m_hSubAgent = DLOpen(szName, szErrorText);
       if (m_hSubAgent != NULL)
index 94280b8..6fc9cc3 100644 (file)
@@ -207,7 +207,7 @@ static BOOL ParseCommandLine(int argc, char *argv[])
                 _tprintf(help_text);
                 return FALSE;
                        case 'v':
-                               _tprintf(_T("NetXMS Server Version ") NETXMS_VERSION_STRING _T(" Build of %hs\n"), __DATE__);
+                               _tprintf(_T("NetXMS Server Version ") NETXMS_VERSION_STRING _T(" Build ") NETXMS_VERSION_BUILD_STRING _T("\n"));
                                return FALSE;
                        case 'c':
 #ifdef UNICODE