Skip to content

Commit aec73db

Browse files
pppanghu77deepin-bot[bot]
authored andcommitted
fix: (timeout)add timeout protection for wireless speed detection
- Include ddlog.h header for logging functionality - Add DDLog namespace usage for enhanced logging capabilities - Implement 3-second timeout protection in getWirelessSpeed method to prevent iw command from hanging during kernel Netlink communication - Add proper error handling with process termination when timeout occurs - Return -1 to indicate failure when wireless speed cannot be obtained Log: fix: (timeout)add timeout protection for wireless speed detection Bug: https://github.com/linuxdeepin/deepin-system-monitor/pull/489/changes
1 parent ac45bcc commit aec73db

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

deepin-system-monitor-main/system/netif.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//
44
// SPDX-License-Identifier: GPL-3.0-or-later
55

6+
#include "ddlog.h"
67
#include "netif.h"
78

89
#include "nl_addr.h"
@@ -20,6 +21,8 @@
2021
#include<unistd.h>
2122
#include<sys/ioctl.h>
2223

24+
using namespace DDLog;
25+
2326
namespace core {
2427
namespace system {
2528

@@ -146,18 +149,26 @@ void NetifInfo::updateBrandInfo()
146149
double NetifInfo::getWirelessSpeed(const QString &interface) {
147150
QProcess process;
148151
process.start("iw", QStringList() << "dev" << interface << "link");
149-
process.waitForFinished();
152+
153+
// 添加3秒超时保护,避免 iw 命令在内核 Netlink 通信时卡死
154+
if (!process.waitForFinished(3000)) {
155+
qCWarning(app) << "iw command timeout for interface:" << interface;
156+
process.kill();
157+
process.waitForFinished();
158+
return -1;
159+
}
160+
150161
QString output = process.readAllStandardOutput();
151162

152163
// 解析发送速率,实测发现控制中心显示的速率是 tx bitrate,所以这里只捕获 tx bitrate
153164
QRegularExpression txRegex("tx bitrate:\\s+(\\d+\\.?\\d*)\\s+(\\w+)");
154165
QRegularExpressionMatch txMatch = txRegex.match(output);
155-
166+
156167
if (txMatch.hasMatch()) {
157168
double rate = txMatch.captured(1).toDouble();
158169
return static_cast<long>(rate);
159170
}
160-
171+
161172
return -1; // 表示无法获取速率
162173
}
163174

0 commit comments

Comments
 (0)