From 92fa40b9227f91d524a362fc24d52b4e8ca34842 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 19 Sep 2017 10:52:37 +0200 Subject: [PATCH] Replace memory-size detection. - drop use of dmidecode to determine exact physical memory size - use sysinfo() to find memory size (assumes linux 2.3.48 or later) --- .../utils/CalamaresUtilsSystem.cpp | 58 +++++++++---------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index c38d398e6..634366e3a 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -26,6 +26,15 @@ #include #include +#ifdef Q_OS_LINUX +#include +#endif + +#ifdef Q_OS_FREEBSD +#include +#include +#endif + namespace CalamaresUtils { @@ -224,47 +233,32 @@ System::targetEnvOutput( const QString& command, qint64 System::getPhysicalMemoryB() { - QProcess p; - p.start( "dmidecode", { "-t", "17" } ); - p.waitForFinished(); - QStringList lines = QString::fromLocal8Bit( p.readAllStandardOutput() ).split( '\n' ); - lines = lines.filter( QRegularExpression( "^\\W*Size:\\W\\d*\\WMB" ) ); - if ( !lines.isEmpty() ) - return 0; - - qint64 availableRamMb = 0; - foreach( const QString& line, lines ) - { - bool ok = false; - availableRamMb += line.simplified() - .split( ' ' ) - .value( 1 ) - .toInt( &ok ); - if ( !ok ) - return 0; - } - qint64 availableRam = availableRamMb * 1024 * 1024; - return availableRam; + return 0; } qint64 System::getTotalMemoryB() { - // A line in meminfo looks like this, with {print $2} we grab the second column. - // MemTotal: 8133432 kB +#ifdef Q_OS_LINUX + struct sysinfo i; + int r = sysinfo( &i ); - QProcess p; - p.start( "awk", { "/MemTotal/ {print $2}", "/proc/meminfo" } ); - p.waitForFinished(); - QString memoryLine = p.readAllStandardOutput().simplified(); - - bool ok = false; - qint64 availableRam = memoryLine.toLongLong( &ok ) * 1024; - if ( !ok ) + if (r) return 0; - return availableRam; + return qint64( i.mem_unit ) * i.totalram; +#elif defined( Q_OS_FREEBSD ) + unsigned long memsize; + size_t s = sizeof(memsize); + + int r = sysctlbyname("vm.kmem_size", &memsize, &s, NULL, 0); + if (r) + return 0; + + return memsize; +#endif + return 0; // Unsupported }