1 Star 0 Fork 25

SuperSix173/procps-ng

forked from src-openEuler/procps-ng 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-ps-don-t-lose-tasks-when-sort-used-with-forest-mode.patch 2.30 KB
一键复制 编辑 原始数据 按行查看 历史
From 09fbd70de33c451dde84254718ded2ccac48aed4 Mon Sep 17 00:00:00 2001
From: Jim Warner <james.warner@comcast.net>
Date: Wed, 20 Sep 2023 00:00:00 -0500
Subject: [PATCH] ps: don't lose tasks when --sort used with forest mode
In an issue cited below the loss of tasks was revealed
whenever the --sort option is used in combination with
forest mode. One could argue against such combinations
and print an error. But we'll take an easier approach.
This patch restores the prior version 3.3.17 behavior.
Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/304
Signed-off-by: Jim Warner <james.warner@comcast.net>
---
src/ps/display.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/ps/display.c b/src/ps/display.c
index e1a3b0da..325edf38 100644
--- a/src/ps/display.c
+++ b/src/ps/display.c
@@ -357,12 +357,12 @@ next_proc:
/***** forest output requires sorting by ppid; add start_time by default */
static void prep_forest_sort(void){
- sort_node *tmp_list = sort_list;
+ sort_node *endp, *tmp_list = sort_list;
const format_struct *incoming;
if(!sort_list) { /* assume start time order */
- incoming = search_format_array("ppid");
- if(!incoming) { fprintf(stderr, _("could not find ppid\n")); exit(1); }
+ incoming = search_format_array("start_time");
+ if(!incoming) { fprintf(stderr, _("could not find start_time\n")); exit(1); }
tmp_list = xmalloc(sizeof(sort_node));
tmp_list->reverse = PIDS_SORT_ASCEND;
tmp_list->typecode = '?'; /* what was this for? */
@@ -371,14 +371,15 @@ static void prep_forest_sort(void){
sort_list = tmp_list;
}
/* this is required for the forest option */
- incoming = search_format_array("start_time");
- if(!incoming) { fprintf(stderr, _("could not find start_time\n")); exit(1); }
+ incoming = search_format_array("ppid");
+ if(!incoming) { fprintf(stderr, _("could not find ppid\n")); exit(1); }
tmp_list = xmalloc(sizeof(sort_node));
tmp_list->reverse = PIDS_SORT_ASCEND;
tmp_list->typecode = '?'; /* what was this for? */
tmp_list->sr = incoming->sr;
- tmp_list->next = sort_list;
- sort_list = tmp_list;
+ tmp_list->next = NULL;
+ endp = sort_list; while(endp->next) endp = endp->next;
+ endp->next = tmp_list;
}
/* we rely on the POSIX requirement for zeroed memory */
--
GitLab
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/SuperSix173/procps-ng.git
git@gitee.com:SuperSix173/procps-ng.git
SuperSix173
procps-ng
procps-ng
master

搜索帮助