Skip to content
Snippets Groups Projects
Commit 3b8092e3 authored by Oz Linden's avatar Oz Linden
Browse files

add OS version string

parent b0125b51
No related branches found
No related tags found
No related merge requests found
...@@ -80,6 +80,7 @@ using namespace llsd; ...@@ -80,6 +80,7 @@ using namespace llsd;
# include <sys/sysinfo.h> # include <sys/sysinfo.h>
# include <stdexcept> # include <stdexcept>
const char MEMINFO_FILE[] = "/proc/meminfo"; const char MEMINFO_FILE[] = "/proc/meminfo";
# include <gnu/libc-version.h>
#elif LL_SOLARIS #elif LL_SOLARIS
# include <stdio.h> # include <stdio.h>
# include <unistd.h> # include <unistd.h>
...@@ -176,7 +177,7 @@ bool get_shell32_dll_version(DWORD& major, DWORD& minor, DWORD& build_number) ...@@ -176,7 +177,7 @@ bool get_shell32_dll_version(DWORD& major, DWORD& minor, DWORD& build_number)
#endif // LL_WINDOWS #endif // LL_WINDOWS
LLOSInfo::LLOSInfo() : LLOSInfo::LLOSInfo() :
mMajorVer(0), mMinorVer(0), mBuild(0) mMajorVer(0), mMinorVer(0), mBuild(0), mOSVersionString("")
{ {
#if LL_WINDOWS #if LL_WINDOWS
...@@ -412,6 +413,102 @@ LLOSInfo::LLOSInfo() : ...@@ -412,6 +413,102 @@ LLOSInfo::LLOSInfo() :
mOSString = mOSStringSimple; mOSString = mOSStringSimple;
} }
#elif LL_LINUX
struct utsname un;
if(uname(&un) != -1)
{
mOSStringSimple.append(un.sysname);
mOSStringSimple.append(" ");
mOSStringSimple.append(un.release);
mOSString = mOSStringSimple;
mOSString.append(" ");
mOSString.append(un.version);
mOSString.append(" ");
mOSString.append(un.machine);
// Simplify 'Simple'
std::string ostype = mOSStringSimple.substr(0, mOSStringSimple.find_first_of(" ", 0));
if (ostype == "Linux")
{
// Only care about major and minor Linux versions, truncate at second '.'
std::string::size_type idx1 = mOSStringSimple.find_first_of(".", 0);
std::string::size_type idx2 = (idx1 != std::string::npos) ? mOSStringSimple.find_first_of(".", idx1+1) : std::string::npos;
std::string simple = mOSStringSimple.substr(0, idx2);
if (simple.length() > 0)
mOSStringSimple = simple;
}
}
else
{
mOSStringSimple.append("Unable to collect OS info");
mOSString = mOSStringSimple;
}
const char* OS_VERSION_MATCH_EXPRESSION[] = "([0-9]+)\.([0-9]+)(\.([0-9]+))?";
boost::regex os_version_parse(OS_VERSION_MATCH_EXPRESSION);
boost::smatch matched;
std::string glibc_version(gnu_get_libc_version());
if ( regex_match_no_exc(glibc_version, matched, os_version_parse) )
{
LL_INFOS("AppInit") << "Using glibc version '" << glibc_version << "' as OS version" << LL_ENDL;
std::string version_value;
if ( matched[1].matched ) // Major version
{
version_value.assign(matched[1].first, matched[1].second);
if (sscanf("%d", &mMajorVer) != 1)
{
LL_WARNS("AppInit") << "failed to parse major version '" << version_value "' as a number" << LL_ENDL;
}
}
else
{
LL_ERRS("AppInit")
<< "OS version regex '" << OS_VERSION_MATCH_EXPRESSION
<< "' returned true, but major version [1] did not match"
<< LL_ENDL;
}
if ( matched[2].matched ) // Minor version
{
version_value.assign(matched[2].first, matched[2].second);
if (sscanf("%d", &mMinorVer) != 1)
{
LL_ERRS("AppInit") << "failed to parse minor version '" << version_value "' as a number" << LL_ENDL;
}
}
else
{
LL_ERRS("AppInit")
<< "OS version regex '" << OS_VERSION_MATCH_EXPRESSION
<< "' returned true, but minor version [1] did not match"
<< LL_ENDL;
}
if ( matched[4].matched ) // Build version (optional) - note that [3] includes the '.'
{
version_value.assign(matched[4].first, matched[4].second);
if (sscanf("%d", &mBuild) != 1)
{
LL_ERRS("AppInit") << "failed to parse build version '" << version_value "' as a number" << LL_ENDL;
}
}
else
{
LL_INFOS("AppInit")
<< "OS build version not provided; using zero"
<< LL_ENDL;
}
}
else
{
LL_WARNS("AppInit") << "glibc version '" << glibc_version << "' cannot be parsed to three numbers; using all zeros" << LL_ENDL;
}
#else #else
struct utsname un; struct utsname un;
...@@ -444,8 +541,13 @@ LLOSInfo::LLOSInfo() : ...@@ -444,8 +541,13 @@ LLOSInfo::LLOSInfo() :
mOSStringSimple.append("Unable to collect OS info"); mOSStringSimple.append("Unable to collect OS info");
mOSString = mOSStringSimple; mOSString = mOSStringSimple;
} }
#endif #endif
std::stringstream dotted_version_string;
dotted_version_string << mMajorVer << "." << mMinorVer << "." << mBuild;
mOSVersionString.append(dotted_version_string.str());
} }
#ifndef LL_WINDOWS #ifndef LL_WINDOWS
...@@ -496,6 +598,11 @@ const std::string& LLOSInfo::getOSStringSimple() const ...@@ -496,6 +598,11 @@ const std::string& LLOSInfo::getOSStringSimple() const
return mOSStringSimple; return mOSStringSimple;
} }
const std::string& LLOSInfo::getOSVersionString() const
{
return mOSVersionString;
}
const S32 STATUS_SIZE = 8192; const S32 STATUS_SIZE = 8192;
//static //static
......
...@@ -49,6 +49,8 @@ class LL_COMMON_API LLOSInfo ...@@ -49,6 +49,8 @@ class LL_COMMON_API LLOSInfo
const std::string& getOSString() const; const std::string& getOSString() const;
const std::string& getOSStringSimple() const; const std::string& getOSStringSimple() const;
const std::string& getOSVersionString() const;
S32 mMajorVer; S32 mMajorVer;
S32 mMinorVer; S32 mMinorVer;
S32 mBuild; S32 mBuild;
...@@ -62,6 +64,7 @@ class LL_COMMON_API LLOSInfo ...@@ -62,6 +64,7 @@ class LL_COMMON_API LLOSInfo
private: private:
std::string mOSString; std::string mOSString;
std::string mOSStringSimple; std::string mOSStringSimple;
std::string mOSVersionString;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment