[Cmake-commits] [cmake-commits] king committed SystemInformation.cxx 1.39 1.40

cmake-commits at cmake.org cmake-commits at cmake.org
Mon Apr 6 14:55:56 EDT 2009


Update of /cvsroot/CMake/CMake/Source/kwsys
In directory public:/mounts/ram/cvs-serv26655/Source/kwsys

Modified Files:
	SystemInformation.cxx 
Log Message:
BUG: Fix parsing of linux 2.6 /proc/meminfo format

Previously KWSys SystemInformation parsed this file assuming a strict
order and set of fields, but the order is not reliable.  This
generalizes the implementation to support any order and extra fields.


Index: SystemInformation.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/kwsys/SystemInformation.cxx,v
retrieving revision 1.39
retrieving revision 1.40
diff -C 2 -d -r1.39 -r1.40
*** SystemInformation.cxx	20 Mar 2009 02:48:05 -0000	1.39
--- SystemInformation.cxx	6 Apr 2009 18:55:54 -0000	1.40
***************
*** 2289,2293 ****
    unsigned long ap=0;
    
!   char buffer[1024]; // for skipping unused lines
    
    int linuxMajor = 0;
--- 2289,2293 ----
    unsigned long ap=0;
    
!   char buffer[1024]; // for reading lines
    
    int linuxMajor = 0;
***************
*** 2332,2385 ****
      // Rigorously, this test should check from the developping version 2.5.x
      // that introduced the new format...
-     
-     unsigned long freeMem;
-     unsigned long buffersMem;
-     unsigned long cachedMem;
  
!     int status;
!     
!     status=fscanf(fd,"MemTotal:%lu kB\n", &this->TotalPhysicalMemory);
!     if(status==1)
!       {
!       status+=fscanf(fd,"MemFree:%lu kB\n", &freeMem);
!       }
!     if(status==2)
!       {
!       status+=fscanf(fd,"Buffers:%lu kB\n", &buffersMem);
!       }
!     if(status==3)
!       {
!       status+=fscanf(fd,"Cached:%lu kB\n", &cachedMem);
!       }
!     if(status==4)
!       {
!       this->TotalPhysicalMemory /= 1024;
!       this->AvailablePhysicalMemory = freeMem+cachedMem+buffersMem;
!       this->AvailablePhysicalMemory /= 1024;
!       }
!     
!     // Skip SwapCached, Active, Inactive, HighTotal, HighFree, LowTotal
!     // and LowFree.
!     int i=0;
!     bool success=status==4;
!     while(i<7 && success)
!       {
!       char *r=fgets(buffer, sizeof(buffer), fd); // skip a line
!       success=r==buffer;
!       ++i;
!       }
!     
!     if(success)
!       {
!       status+=fscanf(fd,"SwapTotal:%lu kB\n", &this->TotalVirtualMemory);
!       }
!     if(status==5)
        {
!       status+=fscanf(fd,"SwapFree:%lu kB\n", &this->AvailableVirtualMemory);
        }
!     if(status==6)
        {
!       this->TotalVirtualMemory /= 1024;
!       this->AvailableVirtualMemory /= 1024;
        }
      else
--- 2332,2361 ----
      // Rigorously, this test should check from the developping version 2.5.x
      // that introduced the new format...
  
!     enum { mMemTotal, mMemFree, mBuffers, mCached, mSwapTotal, mSwapFree };
!     const char* format[6] =
!       { "MemTotal:%lu kB", "MemFree:%lu kB", "Buffers:%lu kB",
!         "Cached:%lu kB", "SwapTotal:%lu kB", "SwapFree:%lu kB" };
!     bool have[6] = { false, false, false, false, false, false };
!     unsigned long value[6];
!     int count = 0;
!     while(fgets(buffer, sizeof(buffer), fd))
        {
!       for(int i=0; i < 6; ++i)
!         {
!         if(!have[i] && sscanf(buffer, format[i], &value[i]) == 1)
!           {
!           have[i] = true;
!           ++count;
!           }
!         }
        }
!     if(count == 6)
        {
!       this->TotalPhysicalMemory = value[mMemTotal] / 1024;
!       this->AvailablePhysicalMemory =
!         (value[mMemFree] + value[mBuffers] + value[mCached]) / 1024;
!       this->TotalVirtualMemory = value[mSwapTotal] / 1024;
!       this->AvailableVirtualMemory = value[mSwapFree] / 1024;
        }
      else



More information about the Cmake-commits mailing list