Skip to content

Commit

Permalink
QSysInfo: fall back to /usr/lib/os-release if the /etc one is missing
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Simon Hausmann <[email protected]>
  • Loading branch information
thiagomacieira committed Aug 8, 2018
1 parent 25feee4 commit 58b6b72
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/corelib/global/qglobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 58b6b72

Please sign in to comment.