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
69 changes: 68 additions & 1 deletion tools/deepin-os-release/main.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,69 @@
// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2017-2026 UnionTech Software Technology Co., Ltd.
//
// 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.
#include <cstdlib>

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

Comment thread
gitee-zeqi marked this conversation as resolved.
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 29 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) {
close(m_readFd); // Close unused file descriptors
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; // Discard this row
}
// Use a loop to ensure complete writing
size_t total = 0;
size_t remaining = strlen(line);
const char *buf = line;
while (total < remaining) {
ssize_t written = write(m_origStderr, buf + total, remaining - total);
if (written < 0) {
if (errno == EINTR)
continue; // Interrupted by signal, retry
break; // Other errors, abandon writing
}
total += written;
}
}
Comment thread
gitee-zeqi marked this conversation as resolved.
free(line);
fclose(readEnd);
}

private:
int m_origStderr;
int m_readFd;
};

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

int main(int argc, char *argv[])
{
// Set filter
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 +183,12 @@
}
}

// clean
dup2(origStderr, STDERR_FILENO); // Restore stderr
close(origStderr);

filterThread->wait();
delete filterThread;

return 0;
}
Loading