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

72 lines
2.6 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
{
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_family", "/sys/class/dmi/id/product_family", &host->productFamily);
2022-09-04 12:43:30 +02:00
getHostProductName(&host->productName);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_version", "/sys/class/dmi/id/product_version", &host->productVersion);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_sku", "/sys/class/dmi/id/product_sku", &host->productSku);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/sys_vendor", "/sys/class/dmi/id/sys_vendor", &host->sysVendor);
2022-09-04 12:43:30 +02:00
//KVM/Qemu virtual machine
if(ffStrbufStartsWithS(&host->productName, "Standard PC"))
ffStrbufPrependS(&host->productName, "KVM/QEMU ");
2022-10-02 17:52:09 +08:00
if(host->productFamily.length == 0 && host->productName.length == 0)
{
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
{
ffStrbufAppendS(&host->productName, "Windows Subsystem for Linux");
2023-07-31 20:29:57 +08:00
if (wslDistroName)
ffStrbufAppendF(&host->productName, " - %s", wslDistroName);
ffStrbufAppendS(&host->productFamily, "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
ffStrbufAppendC(&host->productVersion, 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
}