forked from qt-creator/qt-creator
Journald: Fix reading of entries logged into journald
* Do not use 100% CPU * Do use the correct machine_id Task-number: QTCREATORBUG-14356 Change-Id: Ib6ae9036be83f4f3bb9f7834a1590b492d9a33e1 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -157,8 +157,10 @@ const QByteArray &JournaldWatcher::machineId()
|
|||||||
static QByteArray id;
|
static QByteArray id;
|
||||||
if (id.isEmpty()) {
|
if (id.isEmpty()) {
|
||||||
sd_id128 sdId;
|
sd_id128 sdId;
|
||||||
if (sd_id128_get_machine(&sdId) == 0)
|
if (sd_id128_get_machine(&sdId) == 0) {
|
||||||
id = QByteArray(reinterpret_cast<char *>(sdId.bytes), 16);
|
id.resize(32);
|
||||||
|
sd_id128_to_string(sdId, id.data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -209,6 +211,9 @@ void JournaldWatcher::handleEntry()
|
|||||||
if (!d->m_notifier)
|
if (!d->m_notifier)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (sd_journal_process(d->m_journalContext) != SD_JOURNAL_APPEND)
|
||||||
|
return;
|
||||||
|
|
||||||
LogEntry logEntry;
|
LogEntry logEntry;
|
||||||
forever {
|
forever {
|
||||||
logEntry = d->retrieveEntry();
|
logEntry = d->retrieveEntry();
|
||||||
@@ -225,6 +230,7 @@ void JournaldWatcher::handleEntry()
|
|||||||
quint64 pidNum = pid.isEmpty() ? 0 : QString::fromLatin1(pid).toInt();
|
quint64 pidNum = pid.isEmpty() ? 0 : QString::fromLatin1(pid).toInt();
|
||||||
|
|
||||||
QString message = QString::fromUtf8(logEntry.value(QByteArrayLiteral("MESSAGE")));
|
QString message = QString::fromUtf8(logEntry.value(QByteArrayLiteral("MESSAGE")));
|
||||||
|
message.append(QLatin1Char('\n')); // Add newline.
|
||||||
|
|
||||||
emit journaldOutput(pidNum, message);
|
emit journaldOutput(pidNum, message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user