1 Star 0 Fork 26

znzjugod / rasdaemon

forked from src-openEuler / rasdaemon 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0001-rasdaemon-fix-return-value-type-issue-of-read-write-.patch 2.81 KB
一键复制 编辑 原始数据 按行查看 历史
From 2eea64bc7437b0a5dabff52632a372446ddc4765 Mon Sep 17 00:00:00 2001
From: Xiaofei Tan <tanxiaofei@huawei.com>
Date: Thu, 11 May 2023 10:54:26 +0800
Subject: [PATCH 1/3] rasdaemon: fix return value type issue of read/write
function from unistd.h
The return value type of read/write function from unistd.h is ssize_t.
It's signed normally, and return -1 on error. Fix incorrect use in the
function read_ras_event_all_cpus().
BTW, make setting buffer_percent as a separate function.
Fixes: 94750bcf9309 ("rasdaemon: Fix poll() on per_cpu trace_pipe_raw blocks indefinitely")
Signed-off-by: Xiaofei Tan <tanxiaofei@huawei.com>
Signed-off-by: Shiju Jose <shiju.jose@huawei.com>
---
ras-events.c | 45 ++++++++++++++++++++++++++++++---------------
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/ras-events.c b/ras-events.c
index 6e928a3..d08bf37 100644
--- a/ras-events.c
+++ b/ras-events.c
@@ -376,10 +376,37 @@ static int get_num_cpus(struct ras_events *ras)
#endif
}
+static int set_buffer_percent(struct ras_events *ras, int percent)
+{
+ char buf[16];
+ ssize_t size;
+ int res = 0;
+ int fd;
+
+ fd = open_trace(ras, "buffer_percent", O_WRONLY);
+ if (fd >= 0) {
+ /* For the backward compatibility to the old kernels, do not return
+ * if fail to set the buffer_percent.
+ */
+ snprintf(buf, sizeof(buf), "%d", percent);
+ size = write(fd, buf, strlen(buf));
+ if (size <= 0) {
+ log(TERM, LOG_WARNING, "can't write to buffer_percent\n");
+ res = -1;
+ }
+ close(fd);
+ } else {
+ log(TERM, LOG_WARNING, "Can't open buffer_percent\n");
+ res = -1;
+ }
+
+ return res;
+}
+
static int read_ras_event_all_cpus(struct pthread_data *pdata,
unsigned n_cpus)
{
- unsigned size;
+ ssize_t size;
unsigned long long time_stamp;
void *data;
int ready, i, count_nready;
@@ -391,8 +418,6 @@ static int read_ras_event_all_cpus(struct pthread_data *pdata,
int warnonce[n_cpus];
char pipe_raw[PATH_MAX];
int legacy_kernel = 0;
- int fd;
- char buf[16];
#if 0
int need_sleep = 0;
#endif
@@ -419,18 +444,8 @@ static int read_ras_event_all_cpus(struct pthread_data *pdata,
* Set buffer_percent to 0 so that poll() will return immediately
* when the trace data is available in the ras per_cpu trace pipe_raw
*/
- fd = open_trace(pdata[0].ras, "buffer_percent", O_WRONLY);
- if (fd >= 0) {
- /* For the backward compatibility to the old kernels, do not return
- * if fail to set the buffer_percent.
- */
- snprintf(buf, sizeof(buf), "0");
- size = write(fd, buf, strlen(buf));
- if (size <= 0)
- log(TERM, LOG_WARNING, "can't write to buffer_percent\n");
- close(fd);
- } else
- log(TERM, LOG_WARNING, "Can't open buffer_percent\n");
+ if (set_buffer_percent(pdata[0].ras, 0))
+ log(TERM, LOG_WARNING, "Set buffer_percent failed\n");
for (i = 0; i < (n_cpus + 1); i++)
fds[i].fd = -1;
--
2.25.1
1
https://gitee.com/znzjugod/rasdaemon.git
git@gitee.com:znzjugod/rasdaemon.git
znzjugod
rasdaemon
rasdaemon
master

搜索帮助