From 33ac065b4f33bb4bb43b8ea33f91b6ccbfd400b5 Mon Sep 17 00:00:00 2001 From: liuyuxiu Date: Mon, 25 Nov 2024 13:48:37 +0800 Subject: [PATCH] qos adtapte FDSAN Signed-off-by: liuyuxiu --- services/src/qos_interface.cpp | 37 +++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/services/src/qos_interface.cpp b/services/src/qos_interface.cpp index ebabca7..4c23662 100644 --- a/services/src/qos_interface.cpp +++ b/services/src/qos_interface.cpp @@ -31,7 +31,8 @@ static int TrivalOpenRtgNode(void) { char fileName[] = "/proc/self/sched_rtg_ctrl"; - int fd = open(fileName, O_RDWR); + FILE* f = fopen(fileName, "w+"); + int fd = fileno(f); if (fd < 0) { CONCUR_LOGE("[Interface] task %{public}d belong to user %{public}d open rtg node failed, errno = %{public}d", getpid(), getuid(), errno); @@ -42,7 +43,8 @@ static int TrivalOpenRtgNode(void) static int TrivalOpenQosCtrlNode(void) { char fileName[] = "/proc/thread-self/sched_qos_ctrl"; - int fd = open(fileName, O_RDWR); + FILE* f = fopen(fileName, "w+"); + int fd = fileno(f); if (fd < 0) { CONCUR_LOGE("[Interface] task %{public}d belong to user %{public}d open qos node failed, errno = %{public}d", getpid(), getuid(), errno); @@ -67,8 +69,10 @@ int EnableRtg(bool flag) CONCUR_LOGE("set rtg config enable failed."); } - close(fd); - + FILE* f = fdopen(fd, "w+"); + if (f != nullptr) { + fclose(f); + } return 0; }; @@ -95,7 +99,10 @@ int QosApplyForOther(unsigned int level, int tid) if (ret < 0) { CONCUR_LOGE("[Interface] task %{public}d apply qos failed, errno = %{public}d", tid, errno); } - close(fd); + FILE* f = fdopen(fd, "w+"); + if (f != nullptr) { + fclose(f); + } return ret; } @@ -114,7 +121,10 @@ int QosLeave(void) if (ret < 0) { CONCUR_LOGE("[Interface] task %{public}d leave qos failed, errno = %{public}d", gettid(), errno); } - close(fd); + FILE* f = fdopen(fd, "w+"); + if (f != nullptr) { + fclose(f); + } return ret; } @@ -133,7 +143,10 @@ int QosLeaveForOther(int tid) if (ret < 0) { CONCUR_LOGE("[Interface] task %{public}d leave qos failed, errno = %{public}d", tid, errno); } - close(fd); + FILE* f = fdopen(fd, "w+"); + if (f != nullptr) { + fclose(f); + } return ret; } @@ -148,7 +161,10 @@ int QosPolicySet(const struct QosPolicyDatas* policyDatas) if (ret < 0) { CONCUR_LOGE("[Interface] set qos policy failed, errno = %{public}d", errno); } - close(fd); + FILE* f = fdopen(fd, "w+"); + if (f != nullptr) { + fclose(f); + } return ret; } @@ -176,6 +192,9 @@ int QosGetForOther(int tid, int& level) } level = data.qos; - close(fd); + FILE* f = fdopen(fd, "w+"); + if (f != nullptr) { + fclose(f); + } return ret; } \ No newline at end of file -- Gitee