Ver código fonte

package/petitboot: add patches to fix build errors with "opaque" ncurses

ncurses from 6.4.20231021 enables "NCUSES_OPAQUE_MENU", which hides
some parts of the code away from the application. This causes
petitboot to fail building in a few spots where it tries to directly
access the name of the menu item.

Since the ncurses package was bumped to version 6.5.20250517 in
commit [0], petitboot is failing to build with error:

    ui/ncurses/nc-menu.h: In function ‘pmenu_dump_item’:
    ui/ncurses/nc-menu.h:129:47: error: invalid use of incomplete typedef ‘ITEM’ {aka ‘const struct tagITEM’}
      129 |         pb_debug("%p %s\n", item, (item ? item->name.str : "(null)"));

This commit fixes the issue by adding package patches.
These two patches were submitted to the petitboot mailing list by
Nicholas Piggin [1] resolve this issue using accessors, or by making a new item.

This has been raised upstream but not yet applied [2].

[0]: https://gitlab.com/buildroot.org/buildroot/-/commit/e7c091f11398bdb6498adaa344d0934d97b4ef39
[1]: https://lists.ozlabs.org/pipermail/petitboot/2024-February/thread.html#1545
[2]: https://github.com/open-power/petitboot/issues/106

Signed-off-by: Nathaniel Roach <nroach44@nroach44.id.au>
Fixes: https://autobuild.buildroot.org/results/bf1/bf173e1e0f8ad3f40534aaa358dc40993cd14ac4/build-end.log
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
[Julien:
 - add Signed-off-by in patches
 - add info in commit log
]
Signed-off-by: Julien Olivain <ju.o@free.fr>
Nathaniel Roach 1 semana atrás
pai
commit
1575584f50

+ 67 - 0
package/petitboot/0001-ui-Fix-compile-with-curses-opaque-menu-headers.patch

@@ -0,0 +1,67 @@
+Recent Debian ncurses is built with NCURSES_OPAQUE_MENU, which means
+the menu item type can't be poked directly. Fix with accessors.
+
+One wrinkle is the item name can't be modified, new_item has to be used.
+
+Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
+Upstream: https://github.com/open-power/petitboot/issues/106
+Signed-off-by: Nathaniel Roach <nroach44@nroach44.id.au>
+---
+ ui/ncurses/nc-menu.c | 12 ++++++++----
+ ui/ncurses/nc-menu.h |  4 ++--
+ 2 files changed, 10 insertions(+), 6 deletions(-)
+
+diff --git a/ui/ncurses/nc-menu.c b/ui/ncurses/nc-menu.c
+index a90a02e..a1524b5 100644
+--- a/ui/ncurses/nc-menu.c
++++ b/ui/ncurses/nc-menu.c
+@@ -141,9 +141,13 @@ int pmenu_item_update(struct pmenu_item *item, const char *name)
+ 	if (!label)
+ 		return -1;
+ 
+-	i = item->nci;
+-	i->name.str = label;
+-	i->name.length = strncols(label);
++	i = new_item(label, NULL);
++	if (!i) {
++		talloc_free((char *)label);
++		return -1;
++	}
++	free_item(item->nci);
++	item->nci = i;
+ 
+ 	return 0;
+ }
+@@ -358,7 +362,7 @@ static int pmenu_item_get_index(const struct pmenu_item *item)
+ 				return i;
+ 
+ 	pb_log_fn("not found: %p %s\n", item,
+-		(item ? item->nci->name.str : "(null)"));
++		(item ? item_name(item->nci) : "(null)"));
+ 	return -1;
+ }
+ 
+diff --git a/ui/ncurses/nc-menu.h b/ui/ncurses/nc-menu.h
+index eb568c8..550c7e1 100644
+--- a/ui/ncurses/nc-menu.h
++++ b/ui/ncurses/nc-menu.h
+@@ -126,7 +126,7 @@ static inline struct pmenu *pmenu_from_scr(struct nc_scr *scr)
+ 
+ static inline void pmenu_dump_item(const ITEM *item)
+ {
+-	pb_debug("%p %s\n", item, (item ? item->name.str : "(null)"));
++	pb_debug("%p %s\n", item, (item ? item_name(item) : "(null)"));
+ }
+ 
+ static inline void pmenu_dump_items(ITEM *const *items, unsigned int count)
+@@ -135,7 +135,7 @@ static inline void pmenu_dump_items(ITEM *const *items, unsigned int count)
+ 
+ 	for (i = 0; i < count; i++)
+ 		pb_debug("%u: %p %s\n", i, items[i],
+-			(items[i] ? items[i]->name.str : "(null)"));
++			(items[i] ? item_name(items[i]) : "(null)"));
+ }
+ 
+ #endif
+-- 
+2.42.0

+ 54 - 0
package/petitboot/0002-ui-Fix-curses-menu-item-label-leak.patch

@@ -0,0 +1,54 @@
+When a menu item name is updated, the old label is not freed.
+
+Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
+Upstream: https://github.com/open-power/petitboot/issues/106
+Signed-off-by: Nathaniel Roach <nroach44@nroach44.id.au>
+---
+ ui/ncurses/nc-menu.c | 4 ++++
+ ui/ncurses/nc-menu.h | 1 +
+ 2 files changed, 5 insertions(+)
+
+diff --git a/ui/ncurses/nc-menu.c b/ui/ncurses/nc-menu.c
+index a1524b5..70f2210 100644
+--- a/ui/ncurses/nc-menu.c
++++ b/ui/ncurses/nc-menu.c
+@@ -82,6 +82,7 @@ static void pmenu_resize(struct nc_scr *scr)
+ static int pmenu_item_destructor(void *arg)
+ {
+ 	struct pmenu_item *item = arg;
++	talloc_free((char *)item->label);
+ 	free_item(item->nci);
+ 	return 0;
+ }
+@@ -146,7 +147,9 @@ int pmenu_item_update(struct pmenu_item *item, const char *name)
+ 		talloc_free((char *)label);
+ 		return -1;
+ 	}
++	talloc_free((char *)item->label);
+ 	free_item(item->nci);
++	item->label = label;
+ 	item->nci = i;
+ 
+ 	return 0;
+@@ -168,6 +171,7 @@ struct pmenu_item *pmenu_item_create(struct pmenu *menu, const char *name)
+ 
+ 	item->i_sig = pb_item_sig;
+ 	item->pmenu = menu;
++	item->label = label;
+ 	item->nci = new_item(label, NULL);
+ 
+ 	if (!item->nci) {
+diff --git a/ui/ncurses/nc-menu.h b/ui/ncurses/nc-menu.h
+index 550c7e1..7ba45bf 100644
+--- a/ui/ncurses/nc-menu.h
++++ b/ui/ncurses/nc-menu.h
+@@ -46,6 +46,7 @@ struct pmenu;
+ 
+ struct pmenu_item {
+ 	enum pb_nc_sig i_sig;
++	const char *label;
+ 	ITEM *nci;
+ 	struct pmenu *pmenu;
+ 	void *data;
+-- 
+2.42.0