Skip to content

Commit

Permalink
- extended operating system information with os-release's pretty name
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-lysiuk committed Jan 2, 2021
1 parent 6089c34 commit 1767fdf
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions src/common/platform/posix/sdl/i_main.cpp
Expand Up @@ -40,6 +40,7 @@
#include <new>
#include <sys/param.h>
#include <locale.h>
#include <sys/stat.h>
#include <sys/utsname.h>

#include "engineerrors.h"
Expand Down Expand Up @@ -95,12 +96,50 @@ static int GetCrashInfo (char *buffer, char *end)

void I_DetectOS()
{
FString operatingSystem;

const char *paths[] = {"/etc/os-release", "/usr/lib/os-release"};

for (const char *path : paths)
{
struct stat dummy;

if (stat(path, &dummy) != 0)
continue;

char cmdline[256];
snprintf(cmdline, sizeof cmdline, ". %s && echo ${PRETTY_NAME}", path);

FILE *proc = popen(cmdline, "r");

if (proc == nullptr)
continue;

char distribution[256] = {};
fread(distribution, sizeof distribution - 1, 1, proc);

const size_t length = strlen(distribution);

if (length > 1)
{
distribution[length - 1] = '\0';
operatingSystem = distribution;
}

pclose(proc);
break;
}

utsname unameInfo;
int unameRes = uname(&unameInfo);
if (unameRes != -1)

if (uname(&unameInfo) == 0)
{
Printf("OS: %s %s on %s\n", unameInfo.sysname, unameInfo.release, unameInfo.machine);
const char* const separator = operatingSystem.Len() > 0 ? ", " : "";
operatingSystem.AppendFormat("%s%s %s on %s", separator, unameInfo.sysname, unameInfo.release, unameInfo.machine);
}

if (operatingSystem.Len() > 0)
Printf("OS: %s\n", operatingSystem.GetChars());
}

void I_StartupJoysticks();
Expand Down

0 comments on commit 1767fdf

Please sign in to comment.