Add the FreeBSD default-path for os-release.

Authored by adridg on May 20 2019, 1:11 PM.


  • After much hemming and hawing we ended up with /usr/local/etc/os-release, which isn't one of the standard paths (according to so in spite of us having the file, not all software that looks for it will find it. Patch in the correct path.
  • Patching in the correct path in the original code inserted #ifdefs that interact really badly with the existing code-layout.
  • Switch to iterating over a constant list; with Clang and -O3 this yields slightly smaller code compared to the original. This code is also much easier to #ifdef for specific needs (e.g. for NetBSD and OpenBSD).
Test Plan
  • Included in downstream packaging.
  • Test for functionality:
#include <kosrelease.h>
#include <QDebug>

static void derp(const QString& s)
    qDebug() << s;

    KOSRelease r(s);
    qDebug() << "  name" << 
        << "\n  version" << r.version();

int main(int argc, char **argv)

    return 0;
  • Test for code size:
#include <QtCore/QFile>
#include <QtCore/QString>

QString defaultFilePath()
#ifdef ONE
    if (QFile::exists(QStringLiteral("/etc/os-release"))) {
        return QStringLiteral("/etc/os-release");
    } else if (QFile::exists(QStringLiteral("/usr/lib/os-release"))) {
        return QStringLiteral("/usr/lib/os-release");
    } else {
        return QString();
#ifdef TWO
    for (const auto& path : { 
        }) {
        if (QFile::exists(path)) {
            return path;
    return QString();

Diff Detail

R244 KCoreAddons
No Linters Available
No Unit Test Coverage
Build Status
Buildable 11986
Build 12004: arc lint + arc unit
adridg created this revision.May 20 2019, 1:11 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptMay 20 2019, 1:11 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
adridg requested review of this revision.May 20 2019, 1:11 PM
adridg edited the test plan for this revision. (Show Details)May 20 2019, 1:12 PM
adridg edited the test plan for this revision. (Show Details)

I do wonder if we couldn't just move the freebsd path to the end of the list and drop the ifdef. As far as linux is concerned we still obey the lookup order but simply have an additional path where we may look (and where the file should not ever exist on linux). Conversely on the freebsd side the file should never exist in the other two paths so it would simply fall through to usr/local.

That said, the code is fine, ifdefs just trip me up when reading ^^


& goes on the left of the space please


The indentation is missing a space on every line. Currently it aligns with the bracket when it fact it should align with the arguments after the opening bracket.

adridg abandoned this revision.May 20 2019, 7:32 PM

Thanks for looking at this, Harald. For various downstream packaging reasons, we're going to be stuck with patching, so I'm going to give up on this particular patch.