File indexing completed on 2024-05-19 09:21:34

0001 /*
0002     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003     SPDX-FileCopyrightText: 2019-2022 Harald Sitter <sitter@kde.org>
0004 */
0005 
0006 #pragma once
0007 
0008 #include <QObject>
0009 #include <QSocketNotifier>
0010 
0011 #include <systemd/sd-journal.h>
0012 
0013 #include "memory.h"
0014 
0015 class Coredump;
0016 class CoredumpWatcher : public QObject
0017 {
0018     Q_OBJECT
0019 public:
0020     explicit CoredumpWatcher(std::unique_ptr<sd_journal> context_, QString bootId_, const QString &instance_, QObject *parent = nullptr);
0021 
0022     // must be called before start!
0023     void addMatch(const QString &str);
0024     void start();
0025 
0026 Q_SIGNALS:
0027     void finished();
0028     void error(const QString &msg);
0029     void newDump(const Coredump &dump);
0030     /// Emitted when the current iteration has reached the log end. Roughly meaning that it has loaded all past entries.
0031     void atLogEnd();
0032 
0033 private:
0034     void processLog();
0035     void errnoError(const QString &msg, int err);
0036 
0037     const std::unique_ptr<sd_journal> context = nullptr;
0038     std::unique_ptr<QSocketNotifier> notifier = nullptr;
0039     const QString bootId;
0040     const QString instance;
0041     const QString instanceFilter; // systemd-coredump@%1 instance name
0042     QStringList matches;
0043 };