Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions tools/deepin-os-release/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,52 @@
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#define _GNU_SOURCE

#include "dsysinfo.h"

Check warning on line 7 in tools/deepin-os-release/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dsysinfo.h" not found.

#include <QCoreApplication>

Check warning on line 9 in tools/deepin-os-release/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QCoreApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QCommandLineOption>
#include <QCommandLineParser>
#include <QThread>
#include <QFile>

Check warning on line 13 in tools/deepin-os-release/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFile> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <stdio.h>

Check warning on line 15 in tools/deepin-os-release/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <stdio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <unistd.h>

Check warning on line 16 in tools/deepin-os-release/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <unistd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <cstring>

Check warning on line 17 in tools/deepin-os-release/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <cstring> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DCORE_USE_NAMESPACE

class StderrFilterThread : public QThread
{
public:
explicit StderrFilterThread(int origStderr, int readFd, QObject *parent = nullptr)
: QThread(parent), m_origStderr(origStderr), m_readFd(readFd) {}

protected:
void run() override

Check warning on line 28 in tools/deepin-os-release/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'run' is never used.
{
FILE *readEnd = fdopen(m_readFd, "r");
if (!readEnd) return;

char *line = nullptr;
size_t len = 0;
while (getline(&line, &len, readEnd) != -1) {
if (strstr(line, "WARNING: CPU random generator seem to be failing") ||
strstr(line, "WARNING: RDRND generated:")) {
continue; // 丢弃该行
}
write(m_origStderr, line, strlen(line));
}
free(line);
fclose(readEnd);
}

private:
int m_origStderr;
int m_readFd;
};

bool distributionInfoValid() {
return QFile::exists(DSysInfo::distributionInfoPath());
}
Expand All @@ -27,6 +61,16 @@

int main(int argc, char *argv[])
{
// 设置过滤器
int origStderr = dup(STDERR_FILENO);
int pipefd[2];
pipe(pipefd);
dup2(pipefd[1], STDERR_FILENO);
close(pipefd[1]);

StderrFilterThread *filterThread = new StderrFilterThread(origStderr, pipefd[0]);
filterThread->start();

QCoreApplication app(argc, argv);
Q_UNUSED(app)

Expand Down Expand Up @@ -123,5 +167,12 @@
}
}

// 清理
dup2(origStderr, STDERR_FILENO); // 恢复 stderr
close(origStderr);

filterThread->wait();
delete filterThread;

return 0;
}
Loading