- Fixed server crash after failed SnmpGetInterfaceList()
authorVictor Kirhenshtein <victor@netxms.org>
Wed, 16 Mar 2005 18:02:00 +0000 (18:02 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Wed, 16 Mar 2005 18:02:00 +0000 (18:02 +0000)
- Nodes now binds to template after template applying
- Change log updated

ChangeLog
src/server/core/session.cpp
src/server/core/snmp.cpp
src/server/core/template.cpp
src/server/include/nms_objects.h

index e71c50e..abed03d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+*
+* 0.1.17
+*
+
+- Templates can be manually applied
+- Fixed issue #0000021 (agent crash on multiprocessor Solaris systems)
+- Fixed issue #0000022 (server can crash after unsuccessfull interface
+  configuration poll)
+
+
 *
 * 0.1.16
 *
index a12c3b6..9652b16 100644 (file)
@@ -4181,46 +4181,11 @@ void ClientSession::ApplyTemplate(CSCPMessage *pRequest)
                // Attempt to lock destination's DCI list
                if (((Node *)pDestination)->LockDCIList(m_dwIndex))
                {
-                  DWORD i, dwNumItems, *pdwItemList;
-                  DCItem *pSrcItem, *pDstItem;
-                  int iErrors = 0;
-
-                  dwNumItems = ((Template *)pSource)->GetItemCount();
-                  pdwItemList = (DWORD *)malloc(sizeof(DWORD) * dwNumItems);
-                  DbgPrintf(AF_DEBUG_DC, "Apply %d items from template \"%s\" to node \"%s\"",
-                            dwNumItems, pSource->Name(), pDestination->Name());
-
-                  // Copy items
-                  for(i = 0; i < dwNumItems; i++)
-                  {
-                     pSrcItem = ((Template *)pSource)->GetItemByIndex(i);
-                     pdwItemList[i] = pSrcItem->Id();
-                     if (pSrcItem != NULL)
-                     {
-                        pDstItem = new DCItem(pSrcItem);
-                        pDstItem->SetTemplateId(pSource->Id(), pSrcItem->Id());
-                        pDstItem->ChangeBinding(CreateUniqueId(IDG_ITEM),
-                                                (Template *)pDestination);
-                        if (!((Node *)pDestination)->ApplyTemplateItem(pDstItem))
-                        {
-                           delete pDstItem;
-                           iErrors++;
-                        }
-                     }
-                     else
-                     {
-                        iErrors++;
-                     }
-                  }
-
-                  // Clean items deleted from template
-                  ((Node *)pDestination)->CleanDeletedTemplateItems(pSource->Id(),
-                                                                    dwNumItems, pdwItemList);
+                  BOOL bErrors;
 
-                  // Cleanup
-                  free(pdwItemList);
+                  bErrors = ((Template *)pSource)->ApplyToNode((Node *)pDestination);
                   ((Template *)pDestination)->UnlockDCIList(m_dwIndex);
-                  msg.SetVariable(VID_RCC, (iErrors == 0) ? RCC_SUCCESS : RCC_DCI_COPY_ERRORS);
+                  msg.SetVariable(VID_RCC, bErrors ? RCC_DCI_COPY_ERRORS : RCC_SUCCESS);
                }
                else  // Destination's DCI list already locked by someone else
                {
index 88d791e..d8beef3 100644 (file)
@@ -442,6 +442,7 @@ INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwVersion, DWORD dwAddr,
    else
    {
       DestroyInterfaceList(pIfList);
+      pIfList = NULL;
    }
 
    return pIfList;
index 93ddc8c..cf42ba3 100644 (file)
@@ -566,3 +566,55 @@ DWORD Template::ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked)
 
    return NetObj::ModifyFromMessage(pRequest, TRUE);
 }
+
+
+//
+// Apply template to node
+//
+
+BOOL Template::ApplyToNode(Node *pNode)
+{
+   DWORD i, *pdwItemList;
+   DCItem *pDstItem;
+   BOOL bErrors = FALSE;
+
+   // Link node to template
+   if (!IsChild(pNode->Id()))
+   {
+      AddChild(pNode);
+      pNode->AddParent(this);
+   }
+
+   pdwItemList = (DWORD *)malloc(sizeof(DWORD) * m_dwNumItems);
+   DbgPrintf(AF_DEBUG_DC, "Apply %d items from template \"%s\" to node \"%s\"",
+             m_dwNumItems, m_szName, pNode->Name());
+
+   // Copy items
+   for(i = 0; i < m_dwNumItems; i++)
+   {
+      if (m_ppItems[i] != NULL)
+      {
+         pdwItemList[i] = m_ppItems[i]->Id();
+         pDstItem = new DCItem(m_ppItems[i]);
+         pDstItem->SetTemplateId(m_dwId, m_ppItems[i]->Id());
+         pDstItem->ChangeBinding(CreateUniqueId(IDG_ITEM), pNode);
+         if (!pNode->ApplyTemplateItem(pDstItem))
+         {
+            delete pDstItem;
+            bErrors = TRUE;
+         }
+      }
+      else
+      {
+         bErrors = TRUE;
+      }
+   }
+
+   // Clean items deleted from template
+   pNode->CleanDeletedTemplateItems(m_dwId, m_dwNumItems, pdwItemList);
+
+   // Cleanup
+   free(pdwItemList);
+
+   return bErrors;
+}
index 9ee6f7f..3e79d15 100644 (file)
@@ -95,8 +95,6 @@ extern DWORD g_dwConfigurationPollingInterval;
 // Base class for network objects
 //
 
-class NXCORE_EXPORTABLE Node;
-
 class NXCORE_EXPORTABLE NetObj
 {
 protected:
@@ -270,6 +268,8 @@ public:
    void SetDCIModificationFlag(void) { m_bDCIListModified = TRUE; }
    void SendItemsToClient(ClientSession *pSession, DWORD dwRqId);
    BOOL IsLockedBySession(DWORD dwSessionId) { return m_dwDCILockStatus == dwSessionId; }
+
+   BOOL ApplyToNode(Node *pNode);
 };