Skip to content

Commit

Permalink
MMA: Fix segfault in GetCpuCores (#1242)
Browse files Browse the repository at this point in the history
* Use get_nprocs() to read the number of cores which is simpler and more generic.
  • Loading branch information
jheeks authored and FlorianReimold committed Jan 19, 2024
1 parent fd338fb commit ee0fd91
Showing 1 changed file with 2 additions and 32 deletions.
34 changes: 2 additions & 32 deletions contrib/mma/src/linux/mma_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <string>
#include <unordered_map>
#include <vector>
#include <sys/sysinfo.h>

#include "../include/linux/mma_linux.h"

Expand Down Expand Up @@ -485,38 +486,7 @@ bool MMALinux::MergeBootWithRootARM(ResourceLinux::DiskStatsList& /*disk_stats_i

int MMALinux::GetCpuCores(void)
{
std::list <std::string> cpuinfo_list = TokenizeIntoLines(FileToString("/proc/cpuinfo"));
std::vector <std::string> 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()
Expand Down

0 comments on commit ee0fd91

Please sign in to comment.