Arithmetic exception fixed when disk total size == 0 (e.g. "proc")
authorAlex Kirhenshtein <alk@netxms.org>
Thu, 16 May 2013 00:20:26 +0000 (00:20 +0000)
committerAlex Kirhenshtein <alk@netxms.org>
Thu, 16 May 2013 00:20:26 +0000 (00:20 +0000)
src/agent/subagents/linux/disk.cpp

index 6ab1f16..ce80f74 100644 (file)
@@ -83,13 +83,34 @@ LONG H_DiskInfo(const TCHAR *pszParam, const TCHAR *pArg, TCHAR *pValue)
                                        ret_uint64(pValue, availableBlocks * blockSize);
                                        break;
                                case DISK_USED_PERC:
-                                       ret_double(pValue, (usedBlocks * 100) / totalBlocks);
+               if (totalBlocks > 0)
+               {
+                  ret_double(pValue, (usedBlocks * 100) / totalBlocks);
+               }
+               else
+               {
+                  ret_double(pValue, 0.0);
+               }
                                        break;
                                case DISK_AVAIL_PERC:
-                                       ret_double(pValue, (availableBlocks * 100) / totalBlocks);
+               if (totalBlocks > 0)
+               {
+                  ret_double(pValue, (availableBlocks * 100) / totalBlocks);
+               }
+               else
+               {
+                  ret_double(pValue, 0.0);
+               }
                                        break;
                                case DISK_FREE_PERC:
-                                       ret_double(pValue, (freeBlocks * 100) / totalBlocks);
+               if (totalBlocks > 0)
+               {
+                  ret_double(pValue, (freeBlocks * 100) / totalBlocks);
+               }
+               else
+               {
+                  ret_double(pValue, 0.0);
+               }
                                        break;
                                default:
                                        nRet = SYSINFO_RC_ERROR;