All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] package/lvm2: enable package with musl
@ 2023-03-16 11:36 Simon Rowe
  2023-03-19 16:25 ` Thomas Petazzoni via buildroot
  2023-03-23 14:13 ` [Buildroot] [PATCH v2 1/2] " Simon Rowe
  0 siblings, 2 replies; 10+ messages in thread
From: Simon Rowe @ 2023-03-16 11:36 UTC (permalink / raw)
  To: buildroot; +Cc: Simon Rowe

LVM uses some glibc-specific functions to try and control locking
memory in RAM. As a result the package is currently disabled when
using musl.

Apply patches taken from gentoo:

    https://github.com/gentoo/gentoo/pull/25883
    https://github.com/gentoo/gentoo/pull/26024

and drop the prohibition on musl in Config.in.

Signed-off-by: Simon Rowe <simon.rowe@nutanix.com>
---
 .../lvm2/0001-lvm2-2.03.14-r1-add-fcntl.patch | 25 +++++++++++
 ...002-lvm2-2.03.14-r1-fopen-to-freopen.patch | 44 +++++++++++++++++++
 .../lvm2/0003-lvm2-2.03.14-r1-mallinfo.patch  | 20 +++++++++
 .../lvm2/0004-lvm2-2.03.14-freopen_n2.patch   | 36 +++++++++++++++
 package/lvm2/Config.in                        |  5 ---
 5 files changed, 125 insertions(+), 5 deletions(-)
 create mode 100644 package/lvm2/0001-lvm2-2.03.14-r1-add-fcntl.patch
 create mode 100644 package/lvm2/0002-lvm2-2.03.14-r1-fopen-to-freopen.patch
 create mode 100644 package/lvm2/0003-lvm2-2.03.14-r1-mallinfo.patch
 create mode 100644 package/lvm2/0004-lvm2-2.03.14-freopen_n2.patch

diff --git a/package/lvm2/0001-lvm2-2.03.14-r1-add-fcntl.patch b/package/lvm2/0001-lvm2-2.03.14-r1-add-fcntl.patch
new file mode 100644
index 0000000000..14b3164c3f
--- /dev/null
+++ b/package/lvm2/0001-lvm2-2.03.14-r1-add-fcntl.patch
@@ -0,0 +1,25 @@
+https://bugs.gentoo.org/712336
+https://bugs.gentoo.org/549506
+
+Adds fcntl.h into daemon-server.c to define fcntl and some constants.
+
+Fetch from: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=515ec4557c56cf0e82b95873056c40d8c6269694
+---
+ libdaemon/server/daemon-server.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c
+index 88905a7..771b021 100644
+--- a/libdaemon/server/daemon-server.c
++++ b/libdaemon/server/daemon-server.c
+@@ -28,6 +28,7 @@
+ #include <sys/un.h>
+ #include <unistd.h>
+ #include <signal.h>
++#include <fcntl.h>
+ 
+ #include <syslog.h> /* FIXME. For the global closelog(). */
+ 
+-- 
+2.35.1
+
diff --git a/package/lvm2/0002-lvm2-2.03.14-r1-fopen-to-freopen.patch b/package/lvm2/0002-lvm2-2.03.14-r1-fopen-to-freopen.patch
new file mode 100644
index 0000000000..1d47fdb283
--- /dev/null
+++ b/package/lvm2/0002-lvm2-2.03.14-r1-fopen-to-freopen.patch
@@ -0,0 +1,44 @@
+In musl stdout, stdin and stderr are read-only unlike in glibc.
+This patch changes std* = fopen(...) to freopen(..., std*).
+
+See: https://www.gnu.org/software/libc/manual/html_node/Standard-Streams.html and https://wiki.gentoo.org/wiki/User:Sam/Musl_porting_notes
+
+Fetch from: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=515ec4557c56cf0e82b95873056c40d8c6269694
+---
+ tools/lvmcmdline.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
+index 1e12bed..19da1e5 100644
+--- a/tools/lvmcmdline.c
++++ b/tools/lvmcmdline.c
+@@ -3384,7 +3384,7 @@ static int _check_standard_fds(void)
+ 	int err = is_valid_fd(STDERR_FILENO);
+ 
+ 	if (!is_valid_fd(STDIN_FILENO) &&
+-	    !(stdin = fopen(_PATH_DEVNULL, "r"))) {
++		!freopen(_PATH_DEVNULL, "r", stdin)) {
+ 		if (err)
+ 			perror("stdin stream open");
+ 		else
+@@ -3394,7 +3394,7 @@ static int _check_standard_fds(void)
+ 	}
+ 
+ 	if (!is_valid_fd(STDOUT_FILENO) &&
+-	    !(stdout = fopen(_PATH_DEVNULL, "w"))) {
++		!freopen(_PATH_DEVNULL, "w", stdout)) {
+ 		if (err)
+ 			perror("stdout stream open");
+ 		/* else no stdout */
+@@ -3402,7 +3402,7 @@ static int _check_standard_fds(void)
+ 	}
+ 
+ 	if (!is_valid_fd(STDERR_FILENO) &&
+-	    !(stderr = fopen(_PATH_DEVNULL, "w"))) {
++		!freopen(_PATH_DEVNULL, "w", stderr)) {
+ 		printf("stderr stream open: %s\n",
+ 		       strerror(errno));
+ 		return 0;
+-- 
+2.35.1
+
diff --git a/package/lvm2/0003-lvm2-2.03.14-r1-mallinfo.patch b/package/lvm2/0003-lvm2-2.03.14-r1-mallinfo.patch
new file mode 100644
index 0000000000..d593dca171
--- /dev/null
+++ b/package/lvm2/0003-lvm2-2.03.14-r1-mallinfo.patch
@@ -0,0 +1,20 @@
+https://git.alpinelinux.org/aports/tree/main/lvm2/mallinfo.patch
+
+Patch from Alpine, disables _allocate_memory since mallinfo isn't defined in musl.
+19:17 <@sam_> your caution is well-advised, but it should be safe enough given it's only affecting the non-glibc path
+
+Should be looked back to!
+
+Fetch from: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=515ec4557c56cf0e82b95873056c40d8c6269694
+
+--- ./lib/mm/memlock.c.orig	2015-03-09 11:18:41.560028850 -0100
++++ ./lib/mm/memlock.c	2015-03-09 11:19:54.504373309 -0100
+@@ -137,7 +137,7 @@
+ 
+ static void _allocate_memory(void)
+ {
+-#ifndef VALGRIND_POOL
++#if !defined(VALGRIND_POOL) && defined(__GLIBC__)
+ 	void *stack_mem;
+ 	struct rlimit limit;
+ 	int i, area = 0, missing = _size_malloc_tmp, max_areas = 32, hblks;
diff --git a/package/lvm2/0004-lvm2-2.03.14-freopen_n2.patch b/package/lvm2/0004-lvm2-2.03.14-freopen_n2.patch
new file mode 100644
index 0000000000..d19bc99b7c
--- /dev/null
+++ b/package/lvm2/0004-lvm2-2.03.14-freopen_n2.patch
@@ -0,0 +1,36 @@
+In musl, the standard streams are read-only. To modify them we need to
+use freopen. This patch does the same as lvm2-2.03.14-r1-fopen-to-freopen.patch
+
+https://listman.redhat.com/archives/lvm-devel/2022-June/024203.html
+
+See also:
+https://wiki.gentoo.org/wiki/User:Sam/Musl_porting_notes#error:_assignment_of_read-only_variable_.27.5Bstdout.7Cstdin.7Cstderr.5D.27
+https://www.gnu.org/software/libc/manual/html_node/Standard-Streams.html
+
+Fetch from: http://listman.redhat.com/archives/lvm-devel/attachments/20220621/3594a4a7/attachment.bin
+
+---
+ lib/log/log.c | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/lib/log/log.c b/lib/log/log.c
+index 7b4d537..897c183 100644
+--- a/lib/log/log.c
++++ b/lib/log/log.c
+@@ -207,8 +207,12 @@ int reopen_standard_stream(FILE **stream, const char *mode)
+ 	}
+ 
+ 	_check_and_replace_standard_log_streams(old_stream, new_stream);
+-
++	
++#ifdef __GLIBC__
+ 	*stream = new_stream;
++#else
++	freopen(NULL, mode, *stream);
++#endif
+ 	return 1;
+ }
+ 
+-- 
+2.35.1
+
diff --git a/package/lvm2/Config.in b/package/lvm2/Config.in
index cc740dd40c..577a90656a 100644
--- a/package/lvm2/Config.in
+++ b/package/lvm2/Config.in
@@ -27,15 +27,10 @@ if BR2_PACKAGE_LVM2
 config BR2_PACKAGE_LVM2_STANDARD_INSTALL
 	bool "standard install instead of only dmsetup"
 	default y
-	# http://lists.busybox.net/pipermail/buildroot/2016-August/170592.html
-	depends on !BR2_TOOLCHAIN_USES_MUSL
 	help
 	  Install the standard suite of lvm2 programs. When this option
 	  is not set, only dmsetup is installed.
 
-comment "lvm2 standard install needs a glibc or uClibc toolchain"
-	depends on BR2_TOOLCHAIN_USES_MUSL
-
 endif
 
 comment "lvm2 needs a toolchain w/ threads, dynamic library"
-- 
2.22.3

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

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

end of thread, other threads:[~2023-03-26 21:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-16 11:36 [Buildroot] [PATCH 1/1] package/lvm2: enable package with musl Simon Rowe
2023-03-19 16:25 ` Thomas Petazzoni via buildroot
2023-03-21 13:39   ` Simon Rowe
2023-03-21 13:54     ` Thomas Petazzoni via buildroot
2023-03-23 12:36       ` Simon Rowe
2023-03-23 13:15         ` Thomas Petazzoni via buildroot
2023-03-23 14:13 ` [Buildroot] [PATCH v2 1/2] " Simon Rowe
2023-03-23 14:13   ` [Buildroot] [PATCH v2 2/2] package/multipath-tools: enable " Simon Rowe
2023-03-26 21:11     ` Thomas Petazzoni via buildroot
2023-03-26 21:10   ` [Buildroot] [PATCH v2 1/2] package/lvm2: enable package " Thomas Petazzoni via buildroot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.