From 01450f8b63d12d4cefbf44310f7fa163d3562962 Mon Sep 17 00:00:00 2001 From: yinyongkang Date: Thu, 25 Apr 2024 17:11:56 +0800 Subject: [PATCH] ps: don't lose tasks when --sort used with forest mode (cherry picked from commit 1874138016a46339b9503a7dd7fabd7af97e4bd6) --- ...edge-fix-for-the-lost-tasks-ps-issue.patch | 32 ++++++++++ ...asks-when-sort-used-with-forest-mode.patch | 63 +++++++++++++++++++ procps-ng.spec | 7 ++- 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 backport-acknowledge-fix-for-the-lost-tasks-ps-issue.patch create mode 100644 backport-ps-don-t-lose-tasks-when-sort-used-with-forest-mode.patch diff --git a/backport-acknowledge-fix-for-the-lost-tasks-ps-issue.patch b/backport-acknowledge-fix-for-the-lost-tasks-ps-issue.patch new file mode 100644 index 0000000..77ea2a1 --- /dev/null +++ b/backport-acknowledge-fix-for-the-lost-tasks-ps-issue.patch @@ -0,0 +1,32 @@ +From 92bdeb176f3ce8793ba1a2f3d82525b5c51f7449 Mon Sep 17 00:00:00 2001 +From: Jim Warner +Date: Wed, 4 Oct 2023 12:00:00 -0500 +Subject: [PATCH] NEWS: acknowledge fix for the lost tasks ps issue #304 + +[ and eliminate 1 decades old useless initialization ] + +Reference(s): +. Sep, 2023 - fix for ps issue #304 +commit 09fbd70de33c451dde84254718ded2ccac48aed4 + +Signed-off-by: Jim Warner +--- + src/ps/display.c | 2 +- + 1 files changed, 1 insertions(+), 1 deletion(-) + +diff --git a/src/ps/display.c b/src/ps/display.c +index 325edf38..9b5c7165 100644 +--- a/src/ps/display.c ++++ b/src/ps/display.c +@@ -357,7 +357,7 @@ next_proc: + + /***** forest output requires sorting by ppid; add start_time by default */ + static void prep_forest_sort(void){ +- sort_node *endp, *tmp_list = sort_list; ++ sort_node *endp, *tmp_list; + const format_struct *incoming; + + if(!sort_list) { /* assume start time order */ +-- +GitLab + diff --git a/backport-ps-don-t-lose-tasks-when-sort-used-with-forest-mode.patch b/backport-ps-don-t-lose-tasks-when-sort-used-with-forest-mode.patch new file mode 100644 index 0000000..8b4fc11 --- /dev/null +++ b/backport-ps-don-t-lose-tasks-when-sort-used-with-forest-mode.patch @@ -0,0 +1,63 @@ +From 09fbd70de33c451dde84254718ded2ccac48aed4 Mon Sep 17 00:00:00 2001 +From: Jim Warner +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 +--- + 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 + diff --git a/procps-ng.spec b/procps-ng.spec index 564e313..9c1d90c 100644 --- a/procps-ng.spec +++ b/procps-ng.spec @@ -1,6 +1,6 @@ Name: procps-ng Version: 4.0.2 -Release: 12 +Release: 13 Summary: Utilities that provide system information. License: GPL+ and GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ URL: https://sourceforge.net/projects/procps-ng/ @@ -24,6 +24,8 @@ Patch12: backport-vmstat-Print-guest-time.patch Patch13: backport-ps-Fix-possible-buffer-overflow-in-C-option.patch Patch14: backport-ps-Correct-BSD-c-option.patch Patch15: backport-library-address-remaining-cpu-distortions-stat-api.patch +Patch16: backport-ps-don-t-lose-tasks-when-sort-used-with-forest-mode.patch +Patch17: backport-acknowledge-fix-for-the-lost-tasks-ps-issue.patch BuildRequires: ncurses-devel libtool autoconf automake gcc gettext-devel systemd-devel systemd-pam @@ -106,6 +108,9 @@ ln -s %{_bindir}/pidof %{buildroot}%{_sbindir}/pidof %{_mandir}/man* %changelog +* Thu Apr 25 2024 yinyongkang - 4.0.2-13 +- ps: don't lose tasks when --sort used with forest mode + * Tue Apr 02 2024 Liu Chao - 4.0.2-12 - library: address remaining cpu distorrions, api -- Gitee