buildroot.busybox.net archive mirror
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] package/efivar: fix build with musl libc
@ 2022-10-11  8:49 Erico Nunes
  2022-11-10 10:01 ` Erico Nunes
  2022-11-13 11:51 ` Yann E. MORIN
  0 siblings, 2 replies; 3+ messages in thread
From: Erico Nunes @ 2022-10-11  8:49 UTC (permalink / raw)
  To: buildroot

Backport upstream patch to fix build with musl libc.
This patch is only a requirement since efivar 38 and was applied
upstream shortly after the 38 version tag.

Fixes:
http://autobuild.buildroot.net/results/c49d894b109d68e2624074eab8b939fefa3b42ef/

Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
---
 ...04-efisecdb-fix-build-with-musl-libc.patch | 185 ++++++++++++++++++
 1 file changed, 185 insertions(+)
 create mode 100644 package/efivar/0004-efisecdb-fix-build-with-musl-libc.patch

diff --git a/package/efivar/0004-efisecdb-fix-build-with-musl-libc.patch b/package/efivar/0004-efisecdb-fix-build-with-musl-libc.patch
new file mode 100644
index 0000000000..9815a9d0cf
--- /dev/null
+++ b/package/efivar/0004-efisecdb-fix-build-with-musl-libc.patch
@@ -0,0 +1,185 @@
+From cece3ffd5be2f8641eb694513f2b73e5eb97ffd3 Mon Sep 17 00:00:00 2001
+From: Natanael Copa <ncopa@alpinelinux.org>
+Date: Fri, 28 Jan 2022 12:13:30 +0100
+Subject: [PATCH] efisecdb: fix build with musl libc
+
+Refactor code to use POSIX atexit(3) instead of the GNU specific
+on_exit(3).
+
+Resolves: #197
+Resolves: #202
+Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
+[Erico: backport from upstream commit
+cece3ffd5be2f8641eb694513f2b73e5eb97ffd3]
+Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
+---
+ src/compiler.h |  2 --
+ src/efisecdb.c | 68 +++++++++++++++++++-------------------------------
+ 2 files changed, 26 insertions(+), 44 deletions(-)
+
+diff --git a/src/compiler.h b/src/compiler.h
+index e2f18f0..d95fb01 100644
+--- a/src/compiler.h
++++ b/src/compiler.h
+@@ -7,8 +7,6 @@
+ #ifndef COMPILER_H_
+ #define COMPILER_H_
+ 
+-#include <sys/cdefs.h>
+-
+ /* GCC version checking borrowed from glibc. */
+ #if defined(__GNUC__) && defined(__GNUC_MINOR__)
+ #  define GNUC_PREREQ(maj,min) \
+diff --git a/src/efisecdb.c b/src/efisecdb.c
+index f882373..6bd5ad9 100644
+--- a/src/efisecdb.c
++++ b/src/efisecdb.c
+@@ -25,6 +25,10 @@
+ extern char *optarg;
+ extern int optind, opterr, optopt;
+ 
++static efi_secdb_t *secdb = NULL;
++static list_t infiles;
++static list_t actions;
++
+ struct hash_param {
+ 	char *name;
+ 	efi_secdb_type_t algorithm;
+@@ -187,12 +191,11 @@ add_action(list_t *list, action_type_t action_type, const efi_guid_t *owner,
+ }
+ 
+ static void
+-free_actions(int status UNUSED, void *actionsp)
++free_actions(void)
+ {
+-	list_t *actions = (list_t *)actionsp;
+ 	list_t *pos, *tmp;
+ 
+-	for_each_action_safe(pos, tmp, actions) {
++	for_each_action_safe(pos, tmp, &actions) {
+ 		action_t *action = list_entry(pos, action_t, list);
+ 
+ 		list_del(&action->list);
+@@ -202,12 +205,11 @@ free_actions(int status UNUSED, void *actionsp)
+ }
+ 
+ static void
+-free_infiles(int status UNUSED, void *infilesp)
++free_infiles(void)
+ {
+-	list_t *infiles = (list_t *)infilesp;
+ 	list_t *pos, *tmp;
+ 
+-	for_each_ptr_safe(pos, tmp, infiles) {
++	for_each_ptr_safe(pos, tmp, &infiles) {
+ 		ptrlist_t *entry = list_entry(pos, ptrlist_t, list);
+ 
+ 		list_del(&entry->list);
+@@ -216,27 +218,12 @@ free_infiles(int status UNUSED, void *infilesp)
+ }
+ 
+ static void
+-maybe_free_secdb(int status UNUSED, void *voidp)
++maybe_free_secdb(void)
+ {
+-	efi_secdb_t **secdbp = (efi_secdb_t **)voidp;
+-
+-	if (secdbp == NULL || *secdbp == NULL)
++	if (secdb == NULL)
+ 		return;
+ 
+-	efi_secdb_free(*secdbp);
+-}
+-
+-static void
+-maybe_do_unlink(int status, void *filep)
+-{
+-	char **file = (char **)filep;
+-
+-	if (status == 0)
+-		return;
+-	if (file == NULL || *file == NULL)
+-		return;
+-
+-	unlink(*file);
++	efi_secdb_free(secdb);
+ }
+ 
+ static void
+@@ -323,15 +310,6 @@ parse_input_files(list_t *infiles, char **outfile, efi_secdb_t **secdb,
+ 	return status;
+ }
+ 
+-/*
+- * These need to be static globals so that they're not on main's stack when
+- * on_exit() fires.
+- */
+-static efi_secdb_t *secdb = NULL;
+-static list_t infiles;
+-static list_t actions;
+-static char *outfile = NULL;
+-
+ int
+ main(int argc, char *argv[])
+ {
+@@ -351,6 +329,7 @@ main(int argc, char *argv[])
+ 	bool do_sort_data = false;
+ 	bool sort_descending = false;
+ 	int status = 0;
++	char *outfile = NULL;
+ 
+ 	const char sopts[] = ":aAc:dfg:h:i:Lo:rs:t:v?";
+ 	const struct option lopts[] = {
+@@ -376,10 +355,9 @@ main(int argc, char *argv[])
+ 	INIT_LIST_HEAD(&infiles);
+ 	INIT_LIST_HEAD(&actions);
+ 
+-	on_exit(free_actions, &actions);
+-	on_exit(free_infiles, &infiles);
+-	on_exit(maybe_free_secdb, &secdb);
+-	on_exit(maybe_do_unlink, &outfile);
++	atexit(free_actions);
++	atexit(free_infiles);
++	atexit(maybe_free_secdb);
+ 
+ 	/*
+ 	 * parse the command line.
+@@ -587,24 +565,30 @@ sort_err:
+ 	outfd = open(outfile, flags, 0600);
+ 	if (outfd < 0) {
+ 		char *tmpoutfile = outfile;
+-		if (errno == EEXIST)
+-			outfile = NULL;
++		if (errno != EEXIST)
++			unlink(outfile);
+ 		err(1, "could not open \"%s\"", tmpoutfile);
+ 	}
+ 
+ 	rc = ftruncate(outfd, 0);
+-	if (rc < 0)
++	if (rc < 0) {
++		unlink(outfile);
+ 		err(1, "could not truncate output file \"%s\"", outfile);
++	}
+ 
+ 	void *output;
+ 	size_t size = 0;
+ 	rc = efi_secdb_realize(secdb, &output, &size);
+-	if (rc < 0)
++	if (rc < 0) {
++		unlink(outfile);
+ 		secdb_err(1, "could not realize signature list");
++	}
+ 
+ 	rc = write(outfd, output, size);
+-	if (rc < 0)
++	if (rc < 0) {
++		unlink(outfile);
+ 		err(1, "could not write signature list");
++	}
+ 
+ 	close(outfd);
+ 	xfree(output);
+-- 
+2.37.3
+
-- 
2.37.3

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Buildroot] [PATCH] package/efivar: fix build with musl libc
  2022-10-11  8:49 [Buildroot] [PATCH] package/efivar: fix build with musl libc Erico Nunes
@ 2022-11-10 10:01 ` Erico Nunes
  2022-11-13 11:51 ` Yann E. MORIN
  1 sibling, 0 replies; 3+ messages in thread
From: Erico Nunes @ 2022-11-10 10:01 UTC (permalink / raw)
  To: buildroot

Hello,

On Tue, Oct 11, 2022 at 10:49 AM Erico Nunes <nunes.erico@gmail.com> wrote:
>
> Backport upstream patch to fix build with musl libc.
> This patch is only a requirement since efivar 38 and was applied
> upstream shortly after the 38 version tag.
>
> Fixes:
> http://autobuild.buildroot.net/results/c49d894b109d68e2624074eab8b939fefa3b42ef/

Looks like this patch was missed in the queue and that issue is still
generating daily autobuilder failures. Could someone take a look
please?

Thanks

Erico
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Buildroot] [PATCH] package/efivar: fix build with musl libc
  2022-10-11  8:49 [Buildroot] [PATCH] package/efivar: fix build with musl libc Erico Nunes
  2022-11-10 10:01 ` Erico Nunes
@ 2022-11-13 11:51 ` Yann E. MORIN
  1 sibling, 0 replies; 3+ messages in thread
From: Yann E. MORIN @ 2022-11-13 11:51 UTC (permalink / raw)
  To: Erico Nunes; +Cc: buildroot

Erico, All,

On 2022-10-11 10:49 +0200, Erico Nunes spake thusly:
> Backport upstream patch to fix build with musl libc.
> This patch is only a requirement since efivar 38 and was applied
> upstream shortly after the 38 version tag.
> 
> Fixes:
> http://autobuild.buildroot.net/results/c49d894b109d68e2624074eab8b939fefa3b42ef/
> 
> Signed-off-by: Erico Nunes <nunes.erico@gmail.com>

Applied to master, thanks.

Regards,
Yann E. MORIN.

> ---
>  ...04-efisecdb-fix-build-with-musl-libc.patch | 185 ++++++++++++++++++
>  1 file changed, 185 insertions(+)
>  create mode 100644 package/efivar/0004-efisecdb-fix-build-with-musl-libc.patch
> 
> diff --git a/package/efivar/0004-efisecdb-fix-build-with-musl-libc.patch b/package/efivar/0004-efisecdb-fix-build-with-musl-libc.patch
> new file mode 100644
> index 0000000000..9815a9d0cf
> --- /dev/null
> +++ b/package/efivar/0004-efisecdb-fix-build-with-musl-libc.patch
> @@ -0,0 +1,185 @@
> +From cece3ffd5be2f8641eb694513f2b73e5eb97ffd3 Mon Sep 17 00:00:00 2001
> +From: Natanael Copa <ncopa@alpinelinux.org>
> +Date: Fri, 28 Jan 2022 12:13:30 +0100
> +Subject: [PATCH] efisecdb: fix build with musl libc
> +
> +Refactor code to use POSIX atexit(3) instead of the GNU specific
> +on_exit(3).
> +
> +Resolves: #197
> +Resolves: #202
> +Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
> +[Erico: backport from upstream commit
> +cece3ffd5be2f8641eb694513f2b73e5eb97ffd3]
> +Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
> +---
> + src/compiler.h |  2 --
> + src/efisecdb.c | 68 +++++++++++++++++++-------------------------------
> + 2 files changed, 26 insertions(+), 44 deletions(-)
> +
> +diff --git a/src/compiler.h b/src/compiler.h
> +index e2f18f0..d95fb01 100644
> +--- a/src/compiler.h
> ++++ b/src/compiler.h
> +@@ -7,8 +7,6 @@
> + #ifndef COMPILER_H_
> + #define COMPILER_H_
> + 
> +-#include <sys/cdefs.h>
> +-
> + /* GCC version checking borrowed from glibc. */
> + #if defined(__GNUC__) && defined(__GNUC_MINOR__)
> + #  define GNUC_PREREQ(maj,min) \
> +diff --git a/src/efisecdb.c b/src/efisecdb.c
> +index f882373..6bd5ad9 100644
> +--- a/src/efisecdb.c
> ++++ b/src/efisecdb.c
> +@@ -25,6 +25,10 @@
> + extern char *optarg;
> + extern int optind, opterr, optopt;
> + 
> ++static efi_secdb_t *secdb = NULL;
> ++static list_t infiles;
> ++static list_t actions;
> ++
> + struct hash_param {
> + 	char *name;
> + 	efi_secdb_type_t algorithm;
> +@@ -187,12 +191,11 @@ add_action(list_t *list, action_type_t action_type, const efi_guid_t *owner,
> + }
> + 
> + static void
> +-free_actions(int status UNUSED, void *actionsp)
> ++free_actions(void)
> + {
> +-	list_t *actions = (list_t *)actionsp;
> + 	list_t *pos, *tmp;
> + 
> +-	for_each_action_safe(pos, tmp, actions) {
> ++	for_each_action_safe(pos, tmp, &actions) {
> + 		action_t *action = list_entry(pos, action_t, list);
> + 
> + 		list_del(&action->list);
> +@@ -202,12 +205,11 @@ free_actions(int status UNUSED, void *actionsp)
> + }
> + 
> + static void
> +-free_infiles(int status UNUSED, void *infilesp)
> ++free_infiles(void)
> + {
> +-	list_t *infiles = (list_t *)infilesp;
> + 	list_t *pos, *tmp;
> + 
> +-	for_each_ptr_safe(pos, tmp, infiles) {
> ++	for_each_ptr_safe(pos, tmp, &infiles) {
> + 		ptrlist_t *entry = list_entry(pos, ptrlist_t, list);
> + 
> + 		list_del(&entry->list);
> +@@ -216,27 +218,12 @@ free_infiles(int status UNUSED, void *infilesp)
> + }
> + 
> + static void
> +-maybe_free_secdb(int status UNUSED, void *voidp)
> ++maybe_free_secdb(void)
> + {
> +-	efi_secdb_t **secdbp = (efi_secdb_t **)voidp;
> +-
> +-	if (secdbp == NULL || *secdbp == NULL)
> ++	if (secdb == NULL)
> + 		return;
> + 
> +-	efi_secdb_free(*secdbp);
> +-}
> +-
> +-static void
> +-maybe_do_unlink(int status, void *filep)
> +-{
> +-	char **file = (char **)filep;
> +-
> +-	if (status == 0)
> +-		return;
> +-	if (file == NULL || *file == NULL)
> +-		return;
> +-
> +-	unlink(*file);
> ++	efi_secdb_free(secdb);
> + }
> + 
> + static void
> +@@ -323,15 +310,6 @@ parse_input_files(list_t *infiles, char **outfile, efi_secdb_t **secdb,
> + 	return status;
> + }
> + 
> +-/*
> +- * These need to be static globals so that they're not on main's stack when
> +- * on_exit() fires.
> +- */
> +-static efi_secdb_t *secdb = NULL;
> +-static list_t infiles;
> +-static list_t actions;
> +-static char *outfile = NULL;
> +-
> + int
> + main(int argc, char *argv[])
> + {
> +@@ -351,6 +329,7 @@ main(int argc, char *argv[])
> + 	bool do_sort_data = false;
> + 	bool sort_descending = false;
> + 	int status = 0;
> ++	char *outfile = NULL;
> + 
> + 	const char sopts[] = ":aAc:dfg:h:i:Lo:rs:t:v?";
> + 	const struct option lopts[] = {
> +@@ -376,10 +355,9 @@ main(int argc, char *argv[])
> + 	INIT_LIST_HEAD(&infiles);
> + 	INIT_LIST_HEAD(&actions);
> + 
> +-	on_exit(free_actions, &actions);
> +-	on_exit(free_infiles, &infiles);
> +-	on_exit(maybe_free_secdb, &secdb);
> +-	on_exit(maybe_do_unlink, &outfile);
> ++	atexit(free_actions);
> ++	atexit(free_infiles);
> ++	atexit(maybe_free_secdb);
> + 
> + 	/*
> + 	 * parse the command line.
> +@@ -587,24 +565,30 @@ sort_err:
> + 	outfd = open(outfile, flags, 0600);
> + 	if (outfd < 0) {
> + 		char *tmpoutfile = outfile;
> +-		if (errno == EEXIST)
> +-			outfile = NULL;
> ++		if (errno != EEXIST)
> ++			unlink(outfile);
> + 		err(1, "could not open \"%s\"", tmpoutfile);
> + 	}
> + 
> + 	rc = ftruncate(outfd, 0);
> +-	if (rc < 0)
> ++	if (rc < 0) {
> ++		unlink(outfile);
> + 		err(1, "could not truncate output file \"%s\"", outfile);
> ++	}
> + 
> + 	void *output;
> + 	size_t size = 0;
> + 	rc = efi_secdb_realize(secdb, &output, &size);
> +-	if (rc < 0)
> ++	if (rc < 0) {
> ++		unlink(outfile);
> + 		secdb_err(1, "could not realize signature list");
> ++	}
> + 
> + 	rc = write(outfd, output, size);
> +-	if (rc < 0)
> ++	if (rc < 0) {
> ++		unlink(outfile);
> + 		err(1, "could not write signature list");
> ++	}
> + 
> + 	close(outfd);
> + 	xfree(output);
> +-- 
> +2.37.3
> +
> -- 
> 2.37.3
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-13 11:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-11  8:49 [Buildroot] [PATCH] package/efivar: fix build with musl libc Erico Nunes
2022-11-10 10:01 ` Erico Nunes
2022-11-13 11:51 ` Yann E. MORIN

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).