Skip to content

fix(deepin-os-release): Filter out RDRAND hardware random warnings to ensure clean output#560

Open
gitee-zeqi wants to merge 2 commits into
linuxdeepin:masterfrom
gitee-zeqi:master
Open

fix(deepin-os-release): Filter out RDRAND hardware random warnings to ensure clean output#560
gitee-zeqi wants to merge 2 commits into
linuxdeepin:masterfrom
gitee-zeqi:master

Conversation

@gitee-zeqi
Copy link
Copy Markdown

在某些平台,CPU 的硬件随机数指令 RDRAND 持续返回异常值。这导致某些第三方加密库在动态库初始化阶段检测到失败,并向 stderr 输出固定的 WARNING 文本:

WARNING: CPU random generator seem to be failing, disabling hardware random number generation
WARNING: RDRND generated: 0xffffffff 0xffffffff 0xffffffff 0xffffffff

这样会影响到一些项目的cmake编译,如下:

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 4.3

# compile CXX with /usr/bin/c++
CXX_DEFINES = -DDEEPIN_DDE -DDSG_DATA_DIR=\"/usr/share/dsg\" -DDSYSINFO_PREFIX=\"\" -DPREFIX=\"/usr\" -DQT_CONCURRENT_LIB -DQT_CORE_LIB -DQT_DBUS_LIB -DQT_GUI_LIB -DQT_MESSAGELOGCONTEXT -DQT_NETWORK_LIB -DQT_NO_DEBUG -DQT_PRINTSUPPORT_LIB -DQT_SVG_LIB -DQT_WIDGETS_LIB -DQT_X11EXTRAS_LIB -DQT_XML_LIB -DQ_HOST_NAME=\"x86_64\" -DQ_HOST_X86_64 -DQ_OS_DEEPIN_VERSION="\"WARNING: CPU random generator seem to be failing, disabling hardware random number generation
WARNING: RDRND generated: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
25\"" -DQ_OS_VERSION="\"WARNING: CPU random generator seem to be failing, disabling hardware random number generation
WARNING: RDRND generated: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
25.3.1\""

CXX_INCLUDES = -I/home/ocean/Desktop/gxde-top-panel-plugins/obj-x86_64-linux-gnu/frame -I/home/ocean/Desktop/gxde-top-panel-plugins/frame -I/home/ocean/Desktop/gxde-top-panel-plugins/obj-x86_64-linux-gnu/frame/dde-dock_autogen/include -I/usr/include/libdframeworkdbus-2.0 -I/usr/include/x86_64-linux-gnu/qt5/QtGui/5.15.15 -I/usr/include/x86_64-linux-gnu/qt5/QtGui/5.15.15/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore/5.15.15 -I/usr/include/x86_64-linux-gnu/qt5/QtCore/5.15.15/QtCore -I/home/ocean/Desktop/gxde-top-panel-plugins/obj-x86_64-linux-gnu -I/usr/include/x86_64-linux-gnu/qt5/QGSettings -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/sysprof-6 -I/usr/include/libmount -I/usr/include/blkid -I/home/ocean/Desktop/gxde-top-panel-plugins/frame/../interfaces -isystem /usr/include/dtk5/DWidget -isystem /usr/include/dtk5/DGui -isystem /usr/include/dtk5/DCore -isystem /usr/include/dtk5/DLog -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSvg -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -isystem /usr/include/x86_64-linux-gnu/qt5/QtNetwork -isystem /usr/include/x86_64-linux-gnu/qt5/QtDBus -isystem /usr/include/x86_64-linux-gnu/qt5/QtPrintSupport -isystem /usr/include/x86_64-linux-gnu/qt5/QtXml -isystem /usr/include/x86_64-linux-gnu/qt5/QtConcurrent -isystem /usr/include/x86_64-linux-gnu/qt5/QtX11Extras

CXX_FLAGS = -g -Wall -Ofast -std=gnu++14   -DQ_OS_WARNING: CPU RANDOM GENERATOR SEEM TO BE FAILING, DISABLING HARDWARE RANDOM NUMBER GENERATION WARNING: RDRND GENERATED: 0XFFFFFFFF 0XFFFFFFFF 0XFFFFFFFF 0XFFFFFFFF GXDE -DQ_OS_DEEPIN_WARNING: CPU RANDOM GENERATOR SEEM TO BE FAILING, DISABLING HARDWARE RANDOM NUMBER GENERATION WARNING: RDRND GENERATED: 0XFFFFFFFF 0XFFFFFFFF 0XFFFFFFFF 0XFFFFFFFF COMMUNITY -fPIC

在终端的输出,修改前:

/usr/libexec/dtk5/DCore/bin/deepin-os-release --deepin-versionn-version
WARNING: CPU random generator seem to be failing, disabling hardware random number generation
WARNING: RDRND generated: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
25ocean@ocean-hplaptop14sdk0xxx:~/Desktop/gxde-top-panel-plugins$

修改后:

ocean@ocean-hplaptop14sdk0xxx:~/Desktop/dtk5core$ /usr/libexec/dtk5/DCore/bin/deepin-os-release --deepin-version
25ocean@ocean-hplaptop14sdk0xxx:~/Desktop/dtk5core$

解决方法:
添加一个基于管道 + QThread 的 stderr 过滤器,过滤掉警告

@deepin-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gitee-zeqi

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot
Copy link
Copy Markdown
Contributor

Hi @gitee-zeqi. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented May 8, 2026

TAG Bot

New tag: 6.7.41
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #561

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented May 20, 2026

TAG Bot

New tag: 6.7.42
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #563

@zccrs zccrs requested a review from Copilot May 21, 2026 07:06
@zccrs
Copy link
Copy Markdown
Member

zccrs commented May 21, 2026

这是为了不影响deepin-os-version的输出?

@zccrs
Copy link
Copy Markdown
Member

zccrs commented May 21, 2026

“WARNING: CPU random generator seem to be failing, disabling hardware random number generation” 这些是输出到 stderr的吧,deepin-os-version应该是输出stdout(忘记是不是了),如果它俩不是真的混到同一个管道的,应该也不是问题。

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the deepin-os-release tool to suppress specific recurring RDRAND-related WARNING lines emitted to stderr, preventing them from corrupting version-detection output consumed by downstream tooling (e.g., CMake).

Changes:

  • Redirects stderr to a pipe and forwards it through a QThread that filters out two known WARNING patterns.
  • Restores the original stderr at program shutdown and waits for the filter thread to finish.
Comments suppressed due to low confidence (2)

tools/deepin-os-release/main.cpp:69

  • The return values of dup, pipe, and dup2 aren't checked. If any of these fail, stderr may be left in an undefined state (or redirected without a working reader), potentially hanging the process. Add error handling/fallback (e.g., skip filtering when setup fails and ensure fds are closed/restored).
    // 设置过滤器
    int origStderr = dup(STDERR_FILENO);
    int pipefd[2];
    pipe(pipefd);
    dup2(pipefd[1], STDERR_FILENO);
    close(pipefd[1]);

tools/deepin-os-release/main.cpp:175

  • Cleanup order is racy: close(origStderr) happens before filterThread->wait(), but the filter thread may still be forwarding stderr lines using m_origStderr. This can cause EBADF and lost stderr output. Keep origStderr open until after the thread finishes (or dup the fd for the thread and let the thread own/close it).
    // 清理
    dup2(origStderr, STDERR_FILENO);  // 恢复 stderr
    close(origStderr);

    filterThread->wait();             
    delete filterThread;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/deepin-os-release/main.cpp
Comment thread tools/deepin-os-release/main.cpp Outdated
Comment thread tools/deepin-os-release/main.cpp
@gitee-zeqi
Copy link
Copy Markdown
Author

这是为了不影响deepin-os-version的输出?

对,不影响deepin-os-version的输出和cmake编译(抱歉,因本人还是学生现在才回)

@gitee-zeqi
Copy link
Copy Markdown
Author

“WARNING: CPU random generator seem to be failing, disabling hardware random number generation” 这些是输出到 stderr的吧,deepin-os-version应该是输出stdout(忘记是不是了),如果它俩不是真的混到同一个管道的,应该也不是问题。

会影响到调用deepin-os-version的cmake项目编译,cmake会报错,错误如下:
frame/CMakeFiles/dde-dock.dir/flags.make:6: *** 多个目标匹配。 停止。

flags.make里面被污染的地方如下:

CXX_DEFINES = -DDEEPIN_DDE -DDSG_DATA_DIR=\"/usr/share/dsg\" -DDSYSINFO_PREFIX=\"\" -DPREFIX=\"/usr\" -DQT_CONCURRENT_LIB -DQT_CORE_LIB -DQT_DBUS_LIB -DQT_GUI_LIB -DQT_MESSAGELOGCONTEXT -DQT_NETWORK_LIB -DQT_NO_DEBUG -DQT_PRINTSUPPORT_LIB -DQT_SVG_LIB -DQT_WIDGETS_LIB -DQT_X11EXTRAS_LIB -DQT_XML_LIB -DQ_HOST_NAME=\"x86_64\" -DQ_HOST_X86_64 -DQ_OS_DEEPIN_VERSION="\"WARNING: CPU random generator seem to be failing, disabling hardware random number generation
WARNING: RDRND generated: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
25\"" -DQ_OS_VERSION="\"WARNING: CPU random generator seem to be failing, disabling hardware random number generation
WARNING: RDRND generated: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
25.3.1\""

正常这里没有警告,但是不知为什么cmake把警告也一起合并进来了,所以要过滤,调用修改后的deepin-os-version就没有这些警告污染了,而且也能过编译了,证明问题就在这

… ensure clean output

This fix adds a pipe-based stderr filter using QThread, precisely discarding
the known RDRAND warning lines while preserving all other stderr messages.
…ling

- Filter out known RDRAND-related WARNING lines from stderr to prevent
  pollution of stdout when stdout and stderr are merged by CMake.
- Add missing <cstdlib> header for free().
- Close pipe file descriptor when fdopen fails to avoid potential deadlock.
- Wrap write() in a retry loop to handle EINTR and short writes.
- Update SPDX copyright year to 2026.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants