|
|
d34bfe |
diff --git a/ksysguard/ksysguardd/Linux/cpuinfo.c b/ksysguard/ksysguardd/Linux/cpuinfo.c
|
|
|
d34bfe |
index 9427ec0..6e37b68 100644
|
|
|
d34bfe |
--- a/ksysguard/ksysguardd/Linux/cpuinfo.c
|
|
|
d34bfe |
+++ b/ksysguard/ksysguardd/Linux/cpuinfo.c
|
|
|
d34bfe |
@@ -40,8 +40,9 @@ static int numCores = 0; /* Total # of cores */
|
|
|
d34bfe |
static int HighNumCores = 0; /* Highest # of cores ever seen */
|
|
|
d34bfe |
static float* Clocks = 0; /* Array with one entry per core */
|
|
|
d34bfe |
|
|
|
d34bfe |
-#define CPUINFOBUFSIZE (32 * 1024)
|
|
|
d34bfe |
-static char CpuInfoBuf[ CPUINFOBUFSIZE ];
|
|
|
d34bfe |
+/* Enough for 4-6 virtual cores. Larger values will be tried as needed. */
|
|
|
d34bfe |
+static size_t CpuInfoBufSize = 8 * 1024;
|
|
|
d34bfe |
+static char* CpuInfoBuf = NULL;
|
|
|
d34bfe |
static int Dirty = 0;
|
|
|
d34bfe |
static struct SensorModul *CpuInfoSM;
|
|
|
d34bfe |
|
|
|
d34bfe |
@@ -171,9 +172,12 @@ int updateCpuInfo( void )
|
|
|
d34bfe |
return -1;
|
|
|
d34bfe |
}
|
|
|
d34bfe |
|
|
|
d34bfe |
+ if ( CpuInfoBuf == NULL ) {
|
|
|
d34bfe |
+ CpuInfoBuf = malloc( CpuInfoBufSize );
|
|
|
d34bfe |
+ }
|
|
|
d34bfe |
n = 0;
|
|
|
d34bfe |
for(;;) {
|
|
|
d34bfe |
- ssize_t len = read( fd, CpuInfoBuf + n, CPUINFOBUFSIZE - 1 - n );
|
|
|
d34bfe |
+ ssize_t len = read( fd, CpuInfoBuf + n, CpuInfoBufSize - 1 - n );
|
|
|
d34bfe |
if( len < 0 ) {
|
|
|
d34bfe |
print_error( "Failed to read file \'/proc/cpuinfo\'!\n" );
|
|
|
d34bfe |
CpuInfoOK = -1;
|
|
|
d34bfe |
@@ -183,11 +187,14 @@ int updateCpuInfo( void )
|
|
|
d34bfe |
n += len;
|
|
|
d34bfe |
if( len == 0 ) /* reading finished */
|
|
|
d34bfe |
break;
|
|
|
d34bfe |
- if( n == CPUINFOBUFSIZE - 1 ) {
|
|
|
d34bfe |
- log_error( "Internal buffer too small to read \'/proc/cpuinfo\'" );
|
|
|
d34bfe |
- CpuInfoOK = 0;
|
|
|
d34bfe |
- close( fd );
|
|
|
d34bfe |
- return -1;
|
|
|
d34bfe |
+ if( n == CpuInfoBufSize - 1 ) {
|
|
|
d34bfe |
+ /* The buffer was too small. Double its size and keep going. */
|
|
|
d34bfe |
+ size_t new_size = CpuInfoBufSize * 2;
|
|
|
d34bfe |
+ char* new_buffer = malloc( new_size );
|
|
|
d34bfe |
+ memcpy( new_buffer, CpuInfoBuf, n ); /* copy read data */
|
|
|
d34bfe |
+ free( CpuInfoBuf ); /* free old buffer */
|
|
|
d34bfe |
+ CpuInfoBuf = new_buffer; /* remember new buffer and size */
|
|
|
d34bfe |
+ CpuInfoBufSize = new_size;
|
|
|
d34bfe |
}
|
|
|
d34bfe |
}
|
|
|
d34bfe |
|