diff mbox series

[2/2] bsd-headers: Update cdef.h and add error.h

Message ID 20230920043309.265060-2-raj.khem@gmail.com
State New
Headers show
Series [1/2] bsd-headers: Define __CONCAT and __STRING | expand

Commit Message

Khem Raj Sept. 20, 2023, 4:33 a.m. UTC
error.h is used in many packages and we can use this to provide for
these packages and report the portability problems upstream without
patching the packages here.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 meta/recipes-core/musl/bsd-headers.bb      |  4 +-
 meta/recipes-core/musl/bsd-headers/error.h | 60 ++++++++++++++++++++++
 2 files changed, 63 insertions(+), 1 deletion(-)
 create mode 100644 meta/recipes-core/musl/bsd-headers/error.h

Comments

Richard Purdie Sept. 20, 2023, 1:13 p.m. UTC | #1
On Tue, 2023-09-19 at 21:33 -0700, Khem Raj wrote:
> error.h is used in many packages and we can use this to provide for
> these packages and report the portability problems upstream without
> patching the packages here.
> 
> Signed-off-by: Khem Raj <raj.khem@gmail.com>
> ---
>  meta/recipes-core/musl/bsd-headers.bb      |  4 +-
>  meta/recipes-core/musl/bsd-headers/error.h | 60 ++++++++++++++++++++++
>  2 files changed, 63 insertions(+), 1 deletion(-)
>  create mode 100644 meta/recipes-core/musl/bsd-headers/error.h
> 
> diff --git a/meta/recipes-core/musl/bsd-headers.bb b/meta/recipes-core/musl/bsd-headers.bb
> index 887a8160313..91dc239f888 100644
> --- a/meta/recipes-core/musl/bsd-headers.bb
> +++ b/meta/recipes-core/musl/bsd-headers.bb
> @@ -1,7 +1,7 @@
>  # Copyright (C) 2016 Khem Raj <raj.khem@gmail.com>
>  # Released under the MIT license (see COPYING.MIT for the terms)
>  
> -SUMMARY = "BSD compatible headers"
> +SUMMARY = "Legacy compatible headers for musl libc"
>  LICENSE = "BSD-3-Clause & BSD-2-Clause"
>  LIC_FILES_CHKSUM = "file://sys-queue.h;beginline=1;endline=32;md5=c6352b0f03bb448600456547d334b56f"
>  SECTION = "devel"
> @@ -9,6 +9,7 @@ SECTION = "devel"
>  SRC_URI = "file://sys-queue.h \
>             file://sys-tree.h \
>             file://sys-cdefs.h \
> +           file://error.h \
>            "
>  do_configure[noexec] = "1"
>  do_compile[noexec] = "1"
> @@ -21,6 +22,7 @@ do_install() {
>  	install -Dm 0644 ${S}/sys-queue.h ${D}${includedir}/sys/queue.h
>  	install -Dm 0644 ${S}/sys-tree.h ${D}${includedir}/sys/tree.h
>  	install -Dm 0644 ${S}/sys-cdefs.h ${D}${includedir}/sys/cdefs.h
> +	install -Dm 0644 ${S}/error.h ${D}${includedir}/error.h
>  }
>  #
>  # We will skip parsing for non-musl systems
> diff --git a/meta/recipes-core/musl/bsd-headers/error.h b/meta/recipes-core/musl/bsd-headers/error.h
> new file mode 100644
> index 00000000000..9a4e1f8d006
> --- /dev/null
> +++ b/meta/recipes-core/musl/bsd-headers/error.h
> @@ -0,0 +1,60 @@
> +#ifndef _ERROR_H_
> +#define _ERROR_H_
> +
> +#include <stdarg.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <errno.h>
> +
> +#warning usage of non-standard #include <error.h> is deprecated
> +
> +static unsigned int error_message_count = 0;
> +
> +static inline void error(int status, int errnum, const char* format, ...)
> +{
> +	/* should be fflush(stdout), but that's unspecified if stdout has been closed;
> +	 * stick with fflush(NULL) for simplicity (glibc checks if the fd is still valid) */
> +	fflush(NULL);
> +
> +	va_list ap;
> +	fprintf(stderr, "%s: ", program_invocation_name);
> +	va_start(ap, format);
> +	vfprintf(stderr, format, ap);
> +	va_end(ap);
> +	if (errnum)
> +		fprintf(stderr, ": %s", strerror(errnum));
> +	fprintf(stderr, "\n");
> +	error_message_count++;
> +	if (status)
> +		exit(status);
> +}
> +
> +static int error_one_per_line = 0;
> +
> +static inline void error_at_line(int status, int errnum, const char *filename,
> +		unsigned int linenum, const char *format, ...)
> +{
> +	va_list ap;
> +	if (error_one_per_line) {
> +		static const char *old_filename;
> +		static int old_linenum;
> +		if (linenum == old_linenum && filename == old_filename)
> +			return;
> +		old_filename = filename;
> +		old_linenum = linenum;
> +	}
> +	fprintf(stderr, "%s: %s:%u: ", program_invocation_name, filename, linenum);
> +	va_start(ap, format);
> +	vfprintf(stderr, format, ap);
> +	va_end(ap);
> +	if (errnum)
> +		fprintf(stderr, ": %s", strerror(errnum));
> +	fprintf(stderr, "\n");
> +	error_message_count++;
> +	if (status)
> +		exit(status);
> +}
> +
> +
> +#endif	/* _ERROR_H_ */

https://autobuilder.yoctoproject.org/typhoon/#/builders/80/builds/5743/steps/14/logs/stdio

multiconfig.MultiConfig.test_multiconfig fails

along with:

https://autobuilder.yoctoproject.org/typhoon/#/builders/64/builds/7819/steps/11/logs/stdio

and

https://autobuilder.yoctoproject.org/typhoon/#/builders/45/builds/7840/steps/11/logs/stdio

Cheers,

Richard
diff mbox series

Patch

diff --git a/meta/recipes-core/musl/bsd-headers.bb b/meta/recipes-core/musl/bsd-headers.bb
index 887a8160313..91dc239f888 100644
--- a/meta/recipes-core/musl/bsd-headers.bb
+++ b/meta/recipes-core/musl/bsd-headers.bb
@@ -1,7 +1,7 @@ 
 # Copyright (C) 2016 Khem Raj <raj.khem@gmail.com>
 # Released under the MIT license (see COPYING.MIT for the terms)
 
-SUMMARY = "BSD compatible headers"
+SUMMARY = "Legacy compatible headers for musl libc"
 LICENSE = "BSD-3-Clause & BSD-2-Clause"
 LIC_FILES_CHKSUM = "file://sys-queue.h;beginline=1;endline=32;md5=c6352b0f03bb448600456547d334b56f"
 SECTION = "devel"
@@ -9,6 +9,7 @@  SECTION = "devel"
 SRC_URI = "file://sys-queue.h \
            file://sys-tree.h \
            file://sys-cdefs.h \
+           file://error.h \
           "
 do_configure[noexec] = "1"
 do_compile[noexec] = "1"
@@ -21,6 +22,7 @@  do_install() {
 	install -Dm 0644 ${S}/sys-queue.h ${D}${includedir}/sys/queue.h
 	install -Dm 0644 ${S}/sys-tree.h ${D}${includedir}/sys/tree.h
 	install -Dm 0644 ${S}/sys-cdefs.h ${D}${includedir}/sys/cdefs.h
+	install -Dm 0644 ${S}/error.h ${D}${includedir}/error.h
 }
 #
 # We will skip parsing for non-musl systems
diff --git a/meta/recipes-core/musl/bsd-headers/error.h b/meta/recipes-core/musl/bsd-headers/error.h
new file mode 100644
index 00000000000..9a4e1f8d006
--- /dev/null
+++ b/meta/recipes-core/musl/bsd-headers/error.h
@@ -0,0 +1,60 @@ 
+#ifndef _ERROR_H_
+#define _ERROR_H_
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#warning usage of non-standard #include <error.h> is deprecated
+
+static unsigned int error_message_count = 0;
+
+static inline void error(int status, int errnum, const char* format, ...)
+{
+	/* should be fflush(stdout), but that's unspecified if stdout has been closed;
+	 * stick with fflush(NULL) for simplicity (glibc checks if the fd is still valid) */
+	fflush(NULL);
+
+	va_list ap;
+	fprintf(stderr, "%s: ", program_invocation_name);
+	va_start(ap, format);
+	vfprintf(stderr, format, ap);
+	va_end(ap);
+	if (errnum)
+		fprintf(stderr, ": %s", strerror(errnum));
+	fprintf(stderr, "\n");
+	error_message_count++;
+	if (status)
+		exit(status);
+}
+
+static int error_one_per_line = 0;
+
+static inline void error_at_line(int status, int errnum, const char *filename,
+		unsigned int linenum, const char *format, ...)
+{
+	va_list ap;
+	if (error_one_per_line) {
+		static const char *old_filename;
+		static int old_linenum;
+		if (linenum == old_linenum && filename == old_filename)
+			return;
+		old_filename = filename;
+		old_linenum = linenum;
+	}
+	fprintf(stderr, "%s: %s:%u: ", program_invocation_name, filename, linenum);
+	va_start(ap, format);
+	vfprintf(stderr, format, ap);
+	va_end(ap);
+	if (errnum)
+		fprintf(stderr, ": %s", strerror(errnum));
+	fprintf(stderr, "\n");
+	error_message_count++;
+	if (status)
+		exit(status);
+}
+
+
+#endif	/* _ERROR_H_ */