AuroraRuntime/Source/SWInfo/SWInfo.Linux.cpp
J Reece Wilson 6de5cbfb95 [+] Linux: Added bSingleshot API to timerfd backend
[*] NT: Added TTY handle static getter optimization alongside a secret setter API
[*] Made ILoopSource virtual
[+] Linux: Added console TTY stubs
[*] Renamed ConsoleTTY.Linux.cpp -> ConsoleTTY.Unix.cpp
[-] Redundant commented out shm_unlink (zero ref condition should unlink, i believe.)
[+] Added IProcess async pipe transaction getter stubs
[+] Added additional userland env lookup variables: XDG_SESSION_DESKTOP, DESKTOP_SESSION
[+] Unix: AuTime::ns2ts
2022-05-04 16:43:23 +01:00

121 lines
3.0 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: SWInfo.Linux.cpp
Date: 2022-4-6
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "SWInfo.hpp"
#include "SWInfo.Linux.hpp"
namespace Aurora::SWInfo
{
static AuString gKernelString;
static AuString gUserlandBrand;
static AuString gUserlandDesktopEnv;
static AuString gBuildString;
static void SetProcVersion()
{
AuIOFS::ReadString("/proc/version", gBuildString);
if (gBuildString.size() && gBuildString[gBuildString.size() - 1] == '\n')
{
gBuildString.pop_back();
}
}
static void SetVersion(OSInformation &osInfo)
{
char *endPtr;
auto versionItr = gBuildString.find("ersion ");
if (versionItr == AuString::npos) return;
if (versionItr > 2)
{
gKernelString = gBuildString.substr(0, versionItr - 2);
}
auto ptr = gBuildString.c_str() + (7 + AuUInt(versionItr));
osInfo.uKernelMajor = strtoll(ptr, &endPtr, 10);
if (errno == ERANGE) return;
if (*endPtr != '.') return;
endPtr++;
osInfo.uKernelMinor = strtoll(endPtr, &endPtr, 10);
if (errno == ERANGE) return;
if (*endPtr != '.') return;
endPtr++;
osInfo.uKernelPatch = strtoll(endPtr, &endPtr, 10);
}
static void ParseOSRel(OSInformation &osInfo)
{
AuString osRel;
if (!AuIOFS::ReadString("/etc/os-release", osRel)) return;
AuReplaceAll(osRel, "\"", "");
AuList<AuString> versionNumbers;
Parse::SplitNewlines(osRel, [&](const AuString &line)
{
if (AuStartsWith(line, "NAME="))
{
gUserlandBrand = line.substr(5);
}
else if (AuStartsWith(line, "VERSION="))
{
versionNumbers.push_back(line.substr(8));
}
else if (AuStartsWith(line, "VERSION_ID="))
{
versionNumbers.push_back(line.substr(11));
}
else if (AuStartsWith(line, "BUILD_ID="))
{
versionNumbers.push_back(line.substr(9));
}
});
// TODO: parse uUserlandMajor, uUserlandMinor, uUserlandPatch
}
static void SetDesktopWindowManager()
{
const char *name;
name = ::getenv("XDG_CURRENT_DESKTOP");
if (!name)
{
name = ::getenv("XDG_SESSION_DESKTOP");
}
if (!name)
{
name = ::getenv("DESKTOP_SESSION");
}
if (name)
{
gUserlandDesktopEnv = name;
}
}
void InitLinuxInfo(OSInformation &osInfo)
{
osInfo = AuMove(OSInformation(&gKernelString, &gUserlandBrand, &gUserlandDesktopEnv, &gBuildString, Aurora::Build::EPlatform::eEnumInvalid));
SetProcVersion();
SetVersion(osInfo);
ParseOSRel(osInfo);
SetDesktopWindowManager();
}
}