]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mworker: fix sort order of mworker_proc in 'show proc'
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 19 Mar 2026 15:59:23 +0000 (16:59 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 19 Mar 2026 16:51:28 +0000 (17:51 +0100)
Since version 3.1, the display order of old workers in 'show proc' was
accidentally reversed. The oldest worker was shown first and the newest
last, which was not the intended behavior. This regression was introduced
during the master-worker rework.

Fix this by sorting the list during deserialization in
mworker_env_to_proc_list().

An alternative fix would have been to iterate the list in reverse order
in the show proc function, but that approach risks introducing
inconsistencies when backporting to older versions.

Must be backported to 3.1 and later.

src/mworker.c

index 261b7578c3e249c91dacd6c13637febcd74bdf8f..d1513f3ac5d1e4a9664f6b8fe753b2f67a2b6a59 100644 (file)
@@ -223,7 +223,20 @@ int mworker_env_to_proc_list()
                        }
                }
                if (child->pid > 0) {
-                       LIST_APPEND(&proc_list, &child->list);
+                       struct list *insert_pt = &proc_list;
+                       struct mworker_proc *pos;
+
+                        /* insert at the right position in ASC reload order;
+                         * search from the tail since items are sorted most of
+                        * the time
+                         */
+                        list_for_each_entry_rev(pos, &proc_list, list) {
+                               if (pos->reloads <= child->reloads) {
+                                       insert_pt = &pos->list;
+                                       break;
+                               }
+                       }
+                       LIST_INSERT(insert_pt, &child->list);
                } else {
                        mworker_free_child(child);
                }