2016-11-20 17:02:27 +05:30
|
|
|
#include "sys.h"
|
|
|
|
|
2018-03-12 03:30:54 +05:30
|
|
|
#include "distroutils.h"
|
|
|
|
|
2016-11-20 17:02:27 +05:30
|
|
|
#include <sys/utsname.h>
|
2016-11-22 05:27:15 +05:30
|
|
|
#include <fstream>
|
2016-11-20 17:02:27 +05:30
|
|
|
|
2016-11-26 06:48:05 +05:30
|
|
|
Sys::KernelInfo Sys::getKernelInfo()
|
2016-11-20 17:02:27 +05:30
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
Sys::KernelInfo out;
|
|
|
|
struct utsname buf;
|
|
|
|
uname(&buf);
|
|
|
|
out.kernelName = buf.sysname;
|
|
|
|
out.kernelVersion = buf.release;
|
|
|
|
return out;
|
2016-11-20 17:02:27 +05:30
|
|
|
}
|
2016-11-22 05:27:15 +05:30
|
|
|
|
|
|
|
uint64_t Sys::getSystemRam()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
std::string token;
|
|
|
|
std::ifstream file("/proc/meminfo");
|
|
|
|
while(file >> token)
|
|
|
|
{
|
|
|
|
if(token == "MemTotal:")
|
|
|
|
{
|
|
|
|
uint64_t mem;
|
|
|
|
if(file >> mem)
|
|
|
|
{
|
|
|
|
return mem * 1024ull;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ignore rest of the line
|
|
|
|
file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
|
|
|
}
|
|
|
|
return 0; // nothing found
|
2016-11-22 05:27:15 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool Sys::isCPU64bit()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
return isSystem64bit();
|
2016-11-22 05:27:15 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
bool Sys::isSystem64bit()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
// kernel build arch on linux
|
|
|
|
return QSysInfo::currentCpuArchitecture() == "x86_64";
|
2016-11-22 05:27:15 +05:30
|
|
|
}
|
2018-03-12 03:30:54 +05:30
|
|
|
|
|
|
|
Sys::DistributionInfo Sys::getDistributionInfo()
|
|
|
|
{
|
2018-07-15 18:21:05 +05:30
|
|
|
DistributionInfo systemd_info = read_os_release();
|
|
|
|
DistributionInfo lsb_info = read_lsb_release();
|
|
|
|
DistributionInfo legacy_info = read_legacy_release();
|
|
|
|
DistributionInfo result = systemd_info + lsb_info + legacy_info;
|
|
|
|
if(result.distributionName.isNull())
|
|
|
|
{
|
|
|
|
result.distributionName = "unknown";
|
|
|
|
}
|
|
|
|
if(result.distributionVersion.isNull())
|
|
|
|
{
|
|
|
|
if(result.distributionName == "arch")
|
|
|
|
{
|
|
|
|
result.distributionVersion = "rolling";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.distributionVersion = "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2018-03-12 03:30:54 +05:30
|
|
|
}
|