Files
fastfetch/src/detection/host/host_linux.c
T

74 lines
2.8 KiB
C
Raw Normal View History

2022-09-04 12:43:30 +02:00
#include "host.h"
#include "common/io/io.h"
2022-11-17 22:35:40 +08:00
#include "common/processing.h"
2023-06-22 10:45:43 +00:00
#include "util/smbiosHelper.h"
2022-09-04 12:43:30 +02:00
#include <stdlib.h>
static void getHostProductName(FFstrbuf* name)
{
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_name", "/sys/class/dmi/id/product_name", name);
2022-09-04 12:43:30 +02:00
if(name->length > 0)
return;
ffReadFileBuffer("/sys/firmware/devicetree/base/model", name);
2023-06-22 10:45:43 +00:00
if(ffIsSmbiosValueSet(name))
2022-09-04 12:43:30 +02:00
return;
ffReadFileBuffer("/sys/firmware/devicetree/base/banner-name", name);
if(ffIsSmbiosValueSet(name))
return;
2022-09-04 12:43:30 +02:00
//does a clear before the read
ffReadFileBuffer("/tmp/sysinfo/model", name);
2023-06-22 10:45:43 +00:00
if(ffIsSmbiosValueSet(name))
2022-09-04 12:43:30 +02:00
return;
ffStrbufClear(name);
}
2023-06-12 22:53:12 +08:00
const char* ffDetectHost(FFHostResult* host)
2022-09-04 12:43:30 +02:00
{
2024-01-05 20:38:29 +08:00
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_family", "/sys/class/dmi/id/product_family", &host->family);
getHostProductName(&host->name);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_version", "/sys/class/dmi/id/product_version", &host->version);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_sku", "/sys/class/dmi/id/product_sku", &host->sku);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_serial", "/sys/class/dmi/id/product_serial", &host->serial);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_uuid", "/sys/class/dmi/id/product_uuid", &host->uuid);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/sys_vendor", "/sys/class/dmi/id/sys_vendor", &host->vendor);
2022-09-04 12:43:30 +02:00
//KVM/Qemu virtual machine
2024-01-05 20:38:29 +08:00
if(ffStrbufStartsWithS(&host->name, "Standard PC"))
ffStrbufPrependS(&host->name, "KVM/QEMU ");
2022-09-04 12:43:30 +02:00
2024-01-05 20:38:29 +08:00
if(host->family.length == 0 && host->name.length == 0)
2022-10-02 17:52:09 +08:00
{
2023-07-31 20:29:57 +08:00
const char* wslDistroName = getenv("WSL_DISTRO_NAME");
2022-10-02 17:52:09 +08:00
//On WSL, the real host can't be detected. Instead use WSL as host.
2023-07-31 20:29:57 +08:00
if(wslDistroName != NULL || getenv("WSL_DISTRO") != NULL || getenv("WSL_INTEROP") != NULL)
2022-11-17 22:35:40 +08:00
{
2024-01-05 20:38:29 +08:00
ffStrbufAppendS(&host->name, "Windows Subsystem for Linux");
2023-07-31 20:29:57 +08:00
if (wslDistroName)
2024-01-05 20:38:29 +08:00
ffStrbufAppendF(&host->name, " - %s", wslDistroName);
ffStrbufAppendS(&host->family, "WSL");
2022-11-17 22:35:40 +08:00
2023-08-16 16:51:54 +08:00
FF_STRBUF_AUTO_DESTROY wslVer = ffStrbufCreate(); //Wide characters
2022-11-17 22:35:40 +08:00
if(!ffProcessAppendStdOut(&wslVer, (char* const[]){
"wsl.exe",
"--version",
NULL
}) && wslVer.length > 0)
{
ffStrbufSubstrBeforeFirstC(&wslVer, '\r'); //CRLF
ffStrbufSubstrAfterLastC(&wslVer, ' ');
for(uint32_t i = 0; i < wslVer.length; ++i) {
if(wslVer.chars[i]) //don't append \0
2024-01-05 20:38:29 +08:00
ffStrbufAppendC(&host->version, wslVer.chars[i]);
2022-11-17 22:35:40 +08:00
}
}
}
2022-10-02 17:52:09 +08:00
}
2023-06-12 22:53:12 +08:00
return NULL;
2022-09-04 12:43:30 +02:00
}