summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2018-08-07 20:22:27 -0700
committerThiago Macieira <thiago.macieira@intel.com>2018-08-08 20:17:19 +0000
commit58b6b723defd8006c08624d690e32d53db91cc89 (patch)
treed2321b86fc0eda61517b835028b4444f63fd7029 /src/corelib
parent25feee4e061b99edab79503d81f5bd045c6c8e3d (diff)
QSysInfo: fall back to /usr/lib/os-release if the /etc one is missing
Turns out that there are two files and while a lot of distros symlink one to the other, some distros lack the one in /etc. [ChangeLog][QtCore][QSysInfo] Fixed QSysInfo::productType() to properly detect some Linux distributions that ship with a minimal /etc. Change-Id: Ia741b559c24d46c78fb2fffd1548cab414037220 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/qglobal.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index a6990b88f4..b30d690025 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -2211,10 +2211,19 @@ static bool readEtcFile(QUnixOSVersion &v, const char *filename,
return true;
}
-static bool readEtcOsRelease(QUnixOSVersion &v)
+static bool readOsRelease(QUnixOSVersion &v)
{
- return readEtcFile(v, "/etc/os-release", QByteArrayLiteral("ID="),
- QByteArrayLiteral("VERSION_ID="), QByteArrayLiteral("PRETTY_NAME="));
+ QByteArray id = QByteArrayLiteral("ID=");
+ QByteArray versionId = QByteArrayLiteral("VERSION_ID=");
+ QByteArray prettyName = QByteArrayLiteral("PRETTY_NAME=");
+
+ // man os-release(5) says:
+ // The file /etc/os-release takes precedence over /usr/lib/os-release.
+ // Applications should check for the former, and exclusively use its data
+ // if it exists, and only fall back to /usr/lib/os-release if it is
+ // missing.
+ return readEtcFile(v, "/etc/os-release", id, versionId, prettyName) ||
+ readEtcFile(v, "/usr/lib/os-release", id, versionId, prettyName);
}
static bool readEtcLsbRelease(QUnixOSVersion &v)
@@ -2296,7 +2305,7 @@ static bool readEtcDebianVersion(QUnixOSVersion &v)
static bool findUnixOsVersion(QUnixOSVersion &v)
{
- if (readEtcOsRelease(v))
+ if (readOsRelease(v))
return true;
if (readEtcLsbRelease(v))
return true;