global variables for datadir and libdir made exportable and renamed
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 21 May 2015 16:28:50 +0000 (19:28 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 21 May 2015 16:28:50 +0000 (19:28 +0300)
src/server/core/config.cpp
src/server/core/main.cpp
src/server/core/ndd.cpp
src/server/core/package.cpp
src/server/core/pds.cpp
src/server/core/session.cpp
src/server/include/nms_core.h

index 0946b20..c29caf4 100644 (file)
@@ -51,7 +51,7 @@ static NX_CFG_TEMPLATE m_cfgTemplate[] =
    { _T("CodePage"), CT_MB_STRING, 0, 0, 256, 0, g_szCodePage, NULL },
    { _T("CreateCrashDumps"), CT_BOOLEAN64, 0, 0, AF_CATCH_EXCEPTIONS, 0, &g_flags, NULL },
    { _T("DailyLogFileSuffix"), CT_STRING, 0, 0, 64, 0, g_szDailyLogFileSuffix, NULL },
-   { _T("DataDirectory"), CT_STRING, 0, 0, MAX_PATH, 0, g_szDataDir, NULL },
+   { _T("DataDirectory"), CT_STRING, 0, 0, MAX_PATH, 0, g_netxmsdDataDir, NULL },
    { _T("DBDriver"), CT_STRING, 0, 0, MAX_PATH, 0, g_szDbDriver, NULL },
    { _T("DBDrvParams"), CT_STRING, 0, 0, MAX_PATH, 0, g_szDbDrvParams, NULL },
    { _T("DBEncryptedPassword"), CT_STRING, 0, 0, MAX_DB_STRING, 0, s_encryptedDbPassword, NULL },
@@ -63,7 +63,7 @@ static NX_CFG_TEMPLATE m_cfgTemplate[] =
    { _T("DebugLevel"), CT_LONG, 0, 0, 0, 0, &g_debugLevel, &g_debugLevel },
    { _T("DumpDirectory"), CT_STRING, 0, 0, MAX_PATH, 0, g_szDumpDir, NULL },
    { _T("FullCrashDumps"), CT_BOOLEAN64, 0, 0, AF_WRITE_FULL_DUMP, 0, &g_flags, NULL },
-   { _T("LibraryDirectory"), CT_STRING, 0, 0, MAX_PATH, 0, g_szLibDir, NULL },
+   { _T("LibraryDirectory"), CT_STRING, 0, 0, MAX_PATH, 0, g_netxmsdLibDir, NULL },
    { _T("ListenAddress"), CT_STRING, 0, 0, MAX_PATH, 0, g_szListenAddress, NULL },
    { _T("LogFailedSQLQueries"), CT_BOOLEAN64, 0, 0, AF_LOG_SQL_ERRORS, 0, &g_flags, NULL },
    { _T("LogFile"), CT_STRING, 0, 0, MAX_PATH, 0, g_szLogFile, NULL },
@@ -121,10 +121,10 @@ stop_search:
    if ((homeDir != NULL) && (*homeDir != 0))
    {
 #ifdef _WIN32
-      _sntprintf(g_szLibDir, MAX_PATH, _T("%s%slib"), homeDir,
+      _sntprintf(g_netxmsdLibDir, MAX_PATH, _T("%s%slib"), homeDir,
          (homeDir[_tcslen(homeDir) - 1] != FS_PATH_SEPARATOR_CHAR) ? FS_PATH_SEPARATOR : _T(""));
 #else
-      _sntprintf(g_szLibDir, MAX_PATH, _T("%s/lib/netxms"), homeDir);
+      _sntprintf(g_netxmsdLibDir, MAX_PATH, _T("%s/lib/netxms"), homeDir);
 #endif
    }
 
index 1dc37d7..3800596 100644 (file)
@@ -143,8 +143,8 @@ UINT32 g_icmpPingSize;
 UINT32 g_icmpPingTimeout = 1500;    // ICMP ping timeout (milliseconds)
 UINT32 g_auditFlags;
 UINT32 g_slmPollingInterval;
-TCHAR g_szDataDir[MAX_PATH] = _T("");
-TCHAR g_szLibDir[MAX_PATH] = _T("");
+TCHAR NXCORE_EXPORTABLE g_netxmsdDataDir[MAX_PATH] = _T("");
+TCHAR NXCORE_EXPORTABLE g_netxmsdLibDir[MAX_PATH] = _T("");
 int g_dbSyntax = DB_SYNTAX_UNKNOWN;
 UINT32 NXCORE_EXPORTABLE g_processAffinityMask = DEFAULT_AFFINITY_MASK;
 UINT64 g_serverId = 0;
@@ -204,9 +204,9 @@ static BOOL CheckDataDir()
 {
        TCHAR szBuffer[MAX_PATH];
 
-       if (_tchdir(g_szDataDir) == -1)
+       if (_tchdir(g_netxmsdDataDir) == -1)
        {
-               nxlog_write(MSG_INVALID_DATA_DIR, EVENTLOG_ERROR_TYPE, "s", g_szDataDir);
+               nxlog_write(MSG_INVALID_DATA_DIR, EVENTLOG_ERROR_TYPE, "s", g_netxmsdDataDir);
                return FALSE;
        }
 
@@ -217,7 +217,7 @@ static BOOL CheckDataDir()
 #endif
 
        // Create directory for mib files if it doesn't exist
-       _tcscpy(szBuffer, g_szDataDir);
+       _tcscpy(szBuffer, g_netxmsdDataDir);
        _tcscat(szBuffer, DDIR_MIBS);
        if (MKDIR(szBuffer) == -1)
                if (errno != EEXIST)
@@ -227,7 +227,7 @@ static BOOL CheckDataDir()
                }
 
        // Create directory for package files if it doesn't exist
-       _tcscpy(szBuffer, g_szDataDir);
+       _tcscpy(szBuffer, g_netxmsdDataDir);
        _tcscat(szBuffer, DDIR_PACKAGES);
        if (MKDIR(szBuffer) == -1)
                if (errno != EEXIST)
@@ -237,7 +237,7 @@ static BOOL CheckDataDir()
                }
 
        // Create directory for map background images if it doesn't exist
-       _tcscpy(szBuffer, g_szDataDir);
+       _tcscpy(szBuffer, g_netxmsdDataDir);
        _tcscat(szBuffer, DDIR_BACKGROUNDS);
        if (MKDIR(szBuffer) == -1)
                if (errno != EEXIST)
@@ -247,7 +247,7 @@ static BOOL CheckDataDir()
                }
 
        // Create directory for image library is if does't exists
-       _tcscpy(szBuffer, g_szDataDir);
+       _tcscpy(szBuffer, g_netxmsdDataDir);
        _tcscat(szBuffer, DDIR_IMAGES);
        if (MKDIR(szBuffer) == -1)
        {
@@ -259,7 +259,7 @@ static BOOL CheckDataDir()
        }
 
        // Create directory for shared file store if does't exists
-       _tcscpy(szBuffer, g_szDataDir);
+       _tcscpy(szBuffer, g_netxmsdDataDir);
        _tcscat(szBuffer, DDIR_SHARED_FILES);
        if (MKDIR(szBuffer) == -1)
        {
@@ -271,7 +271,7 @@ static BOOL CheckDataDir()
        }
 
        // Create directory for file store if does't exists
-       _tcscpy(szBuffer, g_szDataDir);
+       _tcscpy(szBuffer, g_netxmsdDataDir);
        _tcscat(szBuffer, DDIR_FILES);
        if (MKDIR(szBuffer) == -1)
        {
@@ -353,24 +353,24 @@ static void LoadGlobalConfig()
    if (ConfigReadInt(_T("ResolveDNSToIPOnStatusPoll"), 0))
       g_flags |= AF_RESOLVE_IP_FOR_EACH_STATUS_POLL;
 
-   if (g_szDataDir[0] == 0)
+   if (g_netxmsdDataDir[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);
+         ConfigReadStr(_T("DataDirectory"), g_netxmsdDataDir, MAX_PATH, path);
       }
       else
       {
-         ConfigReadStr(_T("DataDirectory"), g_szDataDir, MAX_PATH, DEFAULT_DATA_DIR);
+         ConfigReadStr(_T("DataDirectory"), g_netxmsdDataDir, MAX_PATH, DEFAULT_DATA_DIR);
       }
-      DbgPrintf(1, _T("Data directory set to %s from server configuration variable"), g_szDataDir);
+      DbgPrintf(1, _T("Data directory set to %s from server configuration variable"), g_netxmsdDataDir);
    }
    else
    {
-      DbgPrintf(1, _T("Using data directory %s"), g_szDataDir);
+      DbgPrintf(1, _T("Using data directory %s"), g_netxmsdDataDir);
    }
 
    g_icmpPingTimeout = ConfigReadInt(_T("IcmpPingTimeout"), 1500);
@@ -401,7 +401,7 @@ static BOOL InitCryptografy()
    SSL_library_init();
    SSL_load_error_strings();
 
-       _tcscpy(szKeyFile, g_szDataDir);
+       _tcscpy(szKeyFile, g_netxmsdDataDir);
        _tcscat(szKeyFile, DFILE_KEYS);
        fd = _topen(szKeyFile, O_RDONLY | O_BINARY);
        g_pServerKey = LoadRSAKeys(szKeyFile);
@@ -568,15 +568,15 @@ BOOL NXCORE_EXPORTABLE Initialize()
        g_serverStartTime = time(NULL);
        srand((unsigned int)g_serverStartTime);
 
-   if (g_szLibDir[0] == 0)
+   if (g_netxmsdLibDir[0] == 0)
    {
       const TCHAR *homeDir = _tgetenv(_T("NETXMS_HOME"));
       if (homeDir != NULL)
       {
 #ifdef _WIN32
-         _sntprintf(g_szLibDir, MAX_PATH, _T("%s\\lib"), homeDir);
+         _sntprintf(g_netxmsdLibDir, MAX_PATH, _T("%s\\lib"), homeDir);
 #else
-         _sntprintf(g_szLibDir, MAX_PATH, _T("%s/lib/netxms"), homeDir);
+         _sntprintf(g_netxmsdLibDir, MAX_PATH, _T("%s/lib/netxms"), homeDir);
 #endif
       }
       else
@@ -586,25 +586,25 @@ BOOL NXCORE_EXPORTABLE Initialize()
          if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\NetXMS\\Server"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
          {
             DWORD size = MAX_PATH * sizeof(TCHAR);
-            if (RegQueryValueEx(hKey, _T("InstallPath"), NULL, NULL, (BYTE *)g_szLibDir, &size) == ERROR_SUCCESS)
+            if (RegQueryValueEx(hKey, _T("InstallPath"), NULL, NULL, (BYTE *)g_netxmsdLibDir, &size) == ERROR_SUCCESS)
             {
-               _tcscat(g_szLibDir, _T("\\lib"));
+               _tcscat(g_netxmsdLibDir, _T("\\lib"));
             }
             else
             {
-               g_szLibDir[0] = 0;
+               g_netxmsdLibDir[0] = 0;
             }
             RegCloseKey(hKey);
          }
-         if (g_szLibDir[0] == 0)
+         if (g_netxmsdLibDir[0] == 0)
          {
-            _tcscpy(g_szLibDir, DEFAULT_LIBDIR);
+            _tcscpy(g_netxmsdLibDir, DEFAULT_LIBDIR);
          }
 #else
-         _tcscpy(g_szLibDir, DEFAULT_LIBDIR);
+         _tcscpy(g_netxmsdLibDir, DEFAULT_LIBDIR);
 #endif
       }
-      DbgPrintf(1, _T("Data directory set to %s from server configuration variable"), g_szDataDir);
+      DbgPrintf(1, _T("Data directory set to %s from server configuration variable"), g_netxmsdDataDir);
    }
 
        if (!(g_flags & AF_USE_SYSLOG))
@@ -934,7 +934,7 @@ retry_db_lock:
        // Start uptime calculator for SLM
        ThreadCreate(UptimeCalculator, 0, NULL);
 
-       DbgPrintf(2, _T("LIBDIR: %s"), g_szLibDir);
+       DbgPrintf(2, _T("LIBDIR: %s"), g_netxmsdLibDir);
 
        // Call startup functions for the modules
    CALL_ALL_MODULES(pfServerStarted, ());
index 5030225..77ea929 100644 (file)
@@ -89,7 +89,7 @@ void LoadNetworkDeviceDrivers()
        memset(s_drivers, 0, sizeof(NetworkDeviceDriver *) * MAX_DEVICE_DRIVERS);
 
        TCHAR path[MAX_PATH];
-       _tcscpy(path, g_szLibDir);
+       _tcscpy(path, g_netxmsdLibDir);
        _tcscat(path, LDIR_NDD);
 
        DbgPrintf(1, _T("Loading network device drivers from %s"), path);
index 8ae4830..c8c738e 100644 (file)
@@ -80,7 +80,7 @@ BOOL IsPackageFileExist(const TCHAR *pszFileName)
 {
    TCHAR szFullPath[MAX_PATH];
 
-   _tcscpy(szFullPath, g_szDataDir);
+   _tcscpy(szFullPath, g_netxmsdDataDir);
    _tcscat(szFullPath, DDIR_PACKAGES);
    _tcscat(szFullPath, FS_PATH_SEPARATOR);
    _tcscat(szFullPath, pszFileName);
@@ -105,7 +105,7 @@ UINT32 UninstallPackage(UINT32 dwPkgId)
       if (DBGetNumRows(hResult) > 0)
       {
          // Delete file from directory
-         _tcscpy(szFileName, g_szDataDir);
+         _tcscpy(szFileName, g_netxmsdDataDir);
          _tcscat(szFileName, DDIR_PACKAGES);
          _tcscat(szFileName, FS_PATH_SEPARATOR);
          _tcscat(szFileName, CHECK_NULL_EX(DBGetField(hResult, 0, 0, szBuffer, MAX_DB_STRING)));
@@ -211,7 +211,7 @@ static THREAD_RESULT THREAD_CALL DeploymentThread(void *pArg)
                pStartup->pSession->sendMessage(&msg);
 
                // Upload package file to agent
-               _tcscpy(szBuffer, g_szDataDir);
+               _tcscpy(szBuffer, g_netxmsdDataDir);
                _tcscat(szBuffer, DDIR_PACKAGES);
                _tcscat(szBuffer, FS_PATH_SEPARATOR);
                _tcscat(szBuffer, pStartup->szPkgFile);
index 9e0ef5a..1b220e7 100644 (file)
@@ -129,7 +129,7 @@ static void LoadDriver(const TCHAR *file)
        if (_tcschr(file, _T('\\')) == NULL)
        {
           TCHAR path[MAX_PATH];
-          _tcscpy(path, g_szLibDir);
+          _tcscpy(path, g_netxmsdLibDir);
           _tcscat(path, LDIR_PDSDRV);
        SetDllDirectory(path);
       resetDllPath = true;
index 0feb618..baa3f9c 100644 (file)
@@ -4435,7 +4435,7 @@ void ClientSession::sendMib(NXCPMessage *request)
    TCHAR szBuffer[MAX_PATH];
 
    // Send compiled MIB file
-   _tcscpy(szBuffer, g_szDataDir);
+   _tcscpy(szBuffer, g_netxmsdDataDir);
    _tcscat(szBuffer, DFILE_COMPILED_MIB);
        sendFile(szBuffer, request->getId(), 0);
 }
@@ -4453,7 +4453,7 @@ void ClientSession::sendMIBTimestamp(UINT32 dwRqId)
    msg.setCode(CMD_REQUEST_COMPLETED);
    msg.setId(dwRqId);
 
-   _tcscpy(szBuffer, g_szDataDir);
+   _tcscpy(szBuffer, g_netxmsdDataDir);
    _tcscat(szBuffer, DFILE_COMPILED_MIB);
    dwResult = SNMPGetMIBTreeTimestamp(szBuffer, &dwTimeStamp);
    if (dwResult == SNMP_ERR_SUCCESS)
@@ -6392,7 +6392,7 @@ void ClientSession::InstallPackage(NXCPMessage *pRequest)
                   // Prepare for file receive
                   if (m_hCurrFile == -1)
                   {
-                     _tcscpy(m_szCurrFileName, g_szDataDir);
+                     _tcscpy(m_szCurrFileName, g_netxmsdDataDir);
                      _tcscat(m_szCurrFileName, DDIR_PACKAGES);
                      _tcscat(m_szCurrFileName, FS_PATH_SEPARATOR);
                      _tcscat(m_szCurrFileName, pszCleanFileName);
@@ -10955,7 +10955,7 @@ void ClientSession::getServerFile(NXCPMessage *pRequest)
 
        if ((m_dwSystemAccess & SYSTEM_ACCESS_READ_FILES) || musicFile)
        {
-      _tcscpy(fname, g_szDataDir);
+      _tcscpy(fname, g_netxmsdDataDir);
       _tcscat(fname, DDIR_FILES);
       _tcscat(fname, FS_PATH_SEPARATOR);
       _tcscat(fname, GetCleanFileName(name));
@@ -11937,7 +11937,7 @@ void ClientSession::sendLibraryImage(NXCPMessage *request)
 
                                msg.setField(VID_IMAGE_PROTECTED, (WORD)DBGetFieldLong(result, 0, 3));
 
-                               _sntprintf(absFileName, MAX_PATH, _T("%s%s%s%s"), g_szDataDir, DDIR_IMAGES, FS_PATH_SEPARATOR, guidText);
+                               _sntprintf(absFileName, MAX_PATH, _T("%s%s%s%s"), g_netxmsdDataDir, DDIR_IMAGES, FS_PATH_SEPARATOR, guidText);
                                DbgPrintf(5, _T("sendLibraryImage: guid=%s, absFileName=%s"), guidText, absFileName);
 
 #ifdef _WIN32
@@ -12094,7 +12094,7 @@ void ClientSession::updateLibraryImage(NXCPMessage *request)
                                if (DBQuery(hdb, query))
                                {
                                        // DB up to date, update file)
-                                       _sntprintf(absFileName, MAX_PATH, _T("%s%s%s%s"), g_szDataDir, DDIR_IMAGES, FS_PATH_SEPARATOR, guidText);
+                                       _sntprintf(absFileName, MAX_PATH, _T("%s%s%s%s"), g_netxmsdDataDir, DDIR_IMAGES, FS_PATH_SEPARATOR, guidText);
                                        DbgPrintf(5, _T("updateLibraryImage: guid=%s, absFileName=%s"), guidText, absFileName);
 
                                        if (m_hCurrFile == -1)
@@ -12366,7 +12366,7 @@ void ClientSession::uploadFileToAgent(NXCPMessage *request)
                                        TCHAR fullPath[MAX_PATH];
 
                                        // Create full path to the file store
-                                       _tcscpy(fullPath, g_szDataDir);
+                                       _tcscpy(fullPath, g_netxmsdDataDir);
                                        _tcscat(fullPath, DDIR_FILES);
                                        _tcscat(fullPath, FS_PATH_SEPARATOR);
                                        nLen = (int)_tcslen(fullPath);
@@ -12445,7 +12445,7 @@ void ClientSession::listServerFileStore(NXCPMessage *request)
 
        if (m_dwSystemAccess & SYSTEM_ACCESS_READ_FILES || musicFiles)
        {
-      _tcscpy(path, g_szDataDir);
+      _tcscpy(path, g_netxmsdDataDir);
       _tcscat(path, DDIR_FILES);
       _TDIR *dir = _topendir(path);
       if (dir != NULL)
@@ -12687,7 +12687,7 @@ void ClientSession::receiveFile(NXCPMessage *request)
       // Prepare for file receive
       if (m_hCurrFile == -1)
       {
-         _tcscpy(m_szCurrFileName, g_szDataDir);
+         _tcscpy(m_szCurrFileName, g_netxmsdDataDir);
                        _tcscat(m_szCurrFileName, DDIR_FILES);
          _tcscat(m_szCurrFileName, FS_PATH_SEPARATOR);
          _tcscat(m_szCurrFileName, cleanFileName);
@@ -12740,7 +12740,7 @@ void ClientSession::deleteFile(NXCPMessage *request)
       request->getFieldAsString(VID_FILE_NAME, fileName, MAX_PATH);
       const TCHAR *cleanFileName = GetCleanFileName(fileName);
 
-      _tcscpy(m_szCurrFileName, g_szDataDir);
+      _tcscpy(m_szCurrFileName, g_netxmsdDataDir);
       _tcscat(m_szCurrFileName, DDIR_FILES);
       _tcscat(m_szCurrFileName, FS_PATH_SEPARATOR);
       _tcscat(m_szCurrFileName, cleanFileName);
index 5714973..e60551f 100644 (file)
@@ -1032,8 +1032,8 @@ extern TCHAR NXCORE_EXPORTABLE g_szListenAddress[];
 #ifndef _WIN32
 extern TCHAR NXCORE_EXPORTABLE g_szPIDFile[];
 #endif
-extern TCHAR g_szDataDir[];
-extern TCHAR g_szLibDir[];
+extern TCHAR NXCORE_EXPORTABLE g_netxmsdDataDir[];
+extern TCHAR NXCORE_EXPORTABLE g_netxmsdLibDir[];
 extern UINT32 NXCORE_EXPORTABLE g_processAffinityMask;
 extern UINT64 g_serverId;
 extern RSA *g_pServerKey;