From 8766373026c808e84345f26c19c9f685337e8491 Mon Sep 17 00:00:00 2001 From: jheeks Date: Wed, 8 Nov 2023 08:47:53 +0100 Subject: [PATCH] MMA: Fix segfault in GetCpuCores (#1242) * Use get_nprocs() to read the number of cores which is simpler and more generic. --- contrib/mma/src/linux/mma_linux.cpp | 34 ++--------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/contrib/mma/src/linux/mma_linux.cpp b/contrib/mma/src/linux/mma_linux.cpp index 23596253d5..07058c08c8 100644 --- a/contrib/mma/src/linux/mma_linux.cpp +++ b/contrib/mma/src/linux/mma_linux.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "../include/linux/mma_linux.h" @@ -485,38 +486,7 @@ bool MMALinux::MergeBootWithRootARM(ResourceLinux::DiskStatsList& /*disk_stats_i int MMALinux::GetCpuCores(void) { - std::list cpuinfo_list = TokenizeIntoLines(FileToString("/proc/cpuinfo")); - std::vector cpucore_vect; - auto idx = 0; - if(!is_vrm) - { - for (auto iter : cpuinfo_list) - { - if (idx == 12) - { - cpucore_vect = SplitLine(iter); - break; - } - idx++; - } - return std::stoi(cpucore_vect[3]); - } - else - { - auto cpu_cores=0; - for (auto iter : cpuinfo_list) - { - cpucore_vect = SplitLine(iter); - for(auto iter1:cpucore_vect) - { - if(iter1.find("processor")!= std::string::npos) - { - cpu_cores++; - } - } - } - return cpu_cores; - } + return get_nprocs(); } bool MMALinux::CheckIfIsALinuxVRM()